Count Items Matching a Rule LeetCode solution in Rust

1
impl Solution {
2
pub fn count_matches(items: Vec<Vec<String>>, rule_key: String, rule_value: String) -> i32 {
3
let mut ans = 0;
4

5
for item in items.iter() {
6
match rule_key.as_str() {
7
"type" => {
8
if (item[0] == rule_value) {
9
ans += 1
10
}
11
}
12
"color" => {
13
if (item[1] == rule_value) {
14
ans += 1
15
}
16
}
17
"name" => {
18
if (item[2] == rule_value) {
19
ans += 1
20
}
21
}
22
_ => (),
23
}
24
}
25

26
ans
27
}
28
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0