Files
CodeTest/leetcode/score-of-a-string/solution_1396021773.rs

5 lines
155 B
Rust

impl Solution {
pub fn score_of_string(s: String) -> i32 {
s.as_bytes().windows(2).rfold(0, |acc, x| acc + x[0].abs_diff(x[1]) as i32)
}
}