MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / is_nice_str

Function is_nice_str

1763-ongest-nice-substring.rs:3–18  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

1pub fn longest_nice_substring(s: String) -> String {
2 use std::collections::HashMap;
3 pub fn is_nice_str(s: &str) -> bool {
4 let mut mmp = HashMap::new();
5 for c in s.chars() {
6 let count = mmp.entry(c).or_insert(0);
7 *count += 1;
8 }
9 let keys: Vec<char> = mmp.into_keys().collect();
10 if keys.len() % 2 !=0 {
11 false
12 } else {
13 let mut tmp: Vec<_> = keys.iter().map(|e|e.to_lowercase().to_string()).collect();
14 tmp.sort_unstable();
15 tmp.dedup();
16 keys.len() % tmp.len() == 0 && keys.len() / tmp.len() == 2
17 }
18 }
19 for i in (2..=s.len()).rev() {
20 for j in 0..=(s.len()-i) {
21 if is_nice_str(&s[j..=j+i-1]) {

Callers 1

longest_nice_substringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected