20250328 finished.

This commit is contained in:
jackfiled 2025-03-28 12:19:48 +08:00
parent 7b042ef4be
commit 7fd29c8f96
2 changed files with 32 additions and 0 deletions

View File

@ -564,3 +564,5 @@ mod p2711_difference_of_number_of_distinct_values_on_diagonals;
mod p2829_determine_the_minimum_sum_of_a_k_avoiding_array;
mod p2712_minimum_cost_to_make_all_characters_equal;
mod p2716_minimize_string_length;

View File

@ -0,0 +1,30 @@
/**
* [2716] Minimize String Length
*/
pub struct Solution {}
// submission codes start here
use std::collections::HashSet;
use std::iter::FromIterator;
impl Solution {
pub fn minimized_string_length(s: String) -> i32 {
let set: HashSet<u8> = HashSet::from_iter(s.bytes());
set.len() as i32
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_2716() {
assert_eq!(3, Solution::minimized_string_length("aaabc".to_owned()));
assert_eq!(3, Solution::minimized_string_length("cbbd".to_owned()));
assert_eq!(2, Solution::minimized_string_length("dddaaa".to_owned()));
}
}