two pointers
We just keep a tight sliding window that contains a string that has just one character $k$ times.\n\nrust []\nimpl Solution {\n    pub fn number_of_substrings(s
We just keep a tight sliding window that contains a string that has just one character $k$ times.\n\n```rust []\nimpl Solution {\n    pub fn number_of_substrings(s: String, k: i32) -> i32 {\n        let s = s.chars().collect::<Vec<char>>();\n        let mut total = 0;\n        let mut i = 0;\n        let mut a = vec![0; 26];\n        let mut valid = 0;\n        for &x in &s {\n            a[x as usize - \'a\' as usize] += 1;\n            if a[x as usize - \'a\' as usize] == k {valid += 1;}\n            if valid == 0 {continue}\n            \n            while valid > 0 {\n                let y = s[i];\n                a[y as usize - \'a\' as usize] -= 1;\n                if a[y as usize - \'a\' as usize] == k - 1 {\n                    valid -= 1;\n                }\n                i += 1;\n            }\n            i -= 1;\n            let y = s[i];\n            a[y as usize - \'a\' as usize] += 1;\n            valid = 1;\n            total += i as i32 + 1;\n        }\n        total\n    }\n}\n```
['Rust']