From c41b628fab252518d83a59512eede55562efb5db Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Mon, 18 Aug 2025 17:22:00 +0800 Subject: [PATCH] feat: add initial implementation of score_of_a_string with main function --- 3110_score_of_a_string/Cargo.lock | 7 +++++++ 3110_score_of_a_string/Cargo.toml | 6 ++++++ 3110_score_of_a_string/src/main.rs | 14 ++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 3110_score_of_a_string/Cargo.lock create mode 100644 3110_score_of_a_string/Cargo.toml create mode 100644 3110_score_of_a_string/src/main.rs diff --git a/3110_score_of_a_string/Cargo.lock b/3110_score_of_a_string/Cargo.lock new file mode 100644 index 0000000..af83c48 --- /dev/null +++ b/3110_score_of_a_string/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "score_of_a_string" +version = "0.1.0" diff --git a/3110_score_of_a_string/Cargo.toml b/3110_score_of_a_string/Cargo.toml new file mode 100644 index 0000000..7433704 --- /dev/null +++ b/3110_score_of_a_string/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "score_of_a_string" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/3110_score_of_a_string/src/main.rs b/3110_score_of_a_string/src/main.rs new file mode 100644 index 0000000..4eb9a5b --- /dev/null +++ b/3110_score_of_a_string/src/main.rs @@ -0,0 +1,14 @@ +fn main() { + println!("{}", Solution::score_of_string("hello".to_string())); +} + +struct Solution; + +impl Solution { + pub fn score_of_string(s: String) -> i32 { + s.chars() + .zip(s.chars().skip(1)) + .map(|(a, b)| (a as i32 - b as i32).abs()) + .sum() + } +}