3110. Score of a String Easy

@problem@discussion
#String



1/**
2 * [3110] Score of a String
3 *
4 * You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.
5 * Return the score of s.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">s = "hello"</span>
10 * Output: <span class="example-io">13</span>
11 * Explanation:
12 * The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, the score of s would be |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">s = "zaz"</span>
17 * Output: <span class="example-io">50</span>
18 * Explanation:
19 * The ASCII values of the characters in s are: 'z' = 122, 'a' = 97. So, the score of s would be |122 - 97| + |97 - 122| = 25 + 25 = 50.
20 * </div>
21 *  
22 * Constraints:
23 * 
24 * 	2 <= s.length <= 100
25 * 	s consists only of lowercase English letters.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/score-of-a-string/
31// discuss: https://leetcode.com/problems/score-of-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn score_of_string(s: String) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_3110() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.