feat: add initial implementation of score_of_a_string with main function

This commit is contained in:
SquidSpirit 2025-08-18 17:22:00 +08:00
parent 2026979f5e
commit c41b628fab
3 changed files with 27 additions and 0 deletions

7
3110_score_of_a_string/Cargo.lock generated Normal file
View File

@ -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"

View File

@ -0,0 +1,6 @@
[package]
name = "score_of_a_string"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -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()
}
}