20250314 finished.
This commit is contained in:
parent
9f09445dab
commit
3c2c63f4ea
|
@ -536,3 +536,5 @@ mod p2012_sum_of_beauty_in_the_array;
|
|||
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;
|
||||
|
|
27
src/problem/p3340_check_balanced_string.rs
Normal file
27
src/problem/p3340_check_balanced_string.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* [3340] Check Balanced String
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn is_balanced(num: String) -> bool {
|
||||
let num: Vec<i32> = num.bytes().map(|x| (x - b'0') as i32).collect();
|
||||
|
||||
num.iter().step_by(2).sum::<i32>() == num.iter().skip(1).step_by(2).sum::<i32>()
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_3340() {
|
||||
assert!(!Solution::is_balanced("1234".to_owned()));
|
||||
assert!(Solution::is_balanced("24123".to_owned()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user