Skip to content

Commit 31cf14c

Browse files
committed
Create 1170-compare-strings-by-frequency-of-the-smallest-character.rs
1 parent 8b4ec28 commit 31cf14c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pub fn num_smaller_by_frequency(queries: Vec<String>, words: Vec<String>) -> Vec<i32> {
2+
pub fn string_to_value(s: String) -> i32 {
3+
let mut cs = s.chars().collect::<Vec<char>>();
4+
let min = cs.clone().into_iter().min().unwrap();
5+
cs.retain(|c|*c == min);
6+
cs.len() as i32
7+
}
8+
let mut ret = vec![];
9+
for q in queries {
10+
let q_value = string_to_value(q);
11+
let mut tmp = 0;
12+
for w in &words {
13+
if string_to_value(w.clone()) > q_value { tmp += 1 }
14+
}
15+
ret.push(tmp)
16+
}
17+
ret
18+
}
19+
20+
fn main() {
21+
let queries = vec!["cbd".to_string()];
22+
let words = vec!["zaaaz".to_string()];
23+
println!("{:?}", num_smaller_by_frequency(queries, words));
24+
let queries = vec!["bbb".to_string(),"cc".to_string()];
25+
let words = vec!["a".to_string(),"aa".to_string(),"aaa".to_string(),"aaaa".to_string()];
26+
println!("{:?}", num_smaller_by_frequency(queries, words));
27+
}

0 commit comments

Comments
 (0)