feat: 2716_minimize_string_length

This commit is contained in:
SquidSpirit 2025-09-19 00:32:09 +08:00
parent efb0b723b1
commit e557afc877
3 changed files with 31 additions and 0 deletions

7
2716_minimize_string_length/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "minimize_string_length"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "minimize_string_length"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,18 @@
pub struct Solution;
impl Solution {
pub fn minimized_string_length(s: String) -> i32 {
let mut result = 0;
let mut table = vec![false; 26];
for c in s.chars() {
let index = c as usize - 'a' as usize;
if !table[index] {
result += 1;
table[index] = true;
}
}
result
}
}