20250315 finished.
This commit is contained in:
		@@ -538,3 +538,5 @@ mod p3305_count_of_substrings_containing_every_vowel_and_k_consonants_i;
 | 
			
		||||
mod p3306_count_of_substrings_containing_every_vowel_and_k_consonants_ii;
 | 
			
		||||
 | 
			
		||||
mod p3340_check_balanced_string;
 | 
			
		||||
 | 
			
		||||
mod p3110_score_of_a_string;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								src/problem/p3110_score_of_a_string.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/problem/p3110_score_of_a_string.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
/**
 | 
			
		||||
 * [3110] Score of a String
 | 
			
		||||
 */
 | 
			
		||||
pub struct Solution {}
 | 
			
		||||
 | 
			
		||||
// submission codes start here
 | 
			
		||||
 | 
			
		||||
impl Solution {
 | 
			
		||||
    pub fn score_of_string(s: String) -> i32 {
 | 
			
		||||
        s.bytes()
 | 
			
		||||
            .zip(s.bytes().skip(1))
 | 
			
		||||
            .map(|(first, second)| first.abs_diff(second) as i32)
 | 
			
		||||
            .sum::<i32>()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// submission codes end
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod tests {
 | 
			
		||||
    use super::*;
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_3110() {
 | 
			
		||||
        assert_eq!(13, Solution::score_of_string("hello".to_owned()));
 | 
			
		||||
        assert_eq!(50, Solution::score_of_string("zaz".to_owned()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user