1773. Count Items Matching a Rule Easy
1/**
2 * [1773] Count Items Matching a Rule
3 *
4 * You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the i^th item. You are also given a rule represented by two strings, ruleKey and ruleValue.
5 * The i^th item is said to match the rule if one of the following is true:
6 *
7 * ruleKey == "type" and ruleValue == typei.
8 * ruleKey == "color" and ruleValue == colori.
9 * ruleKey == "name" and ruleValue == namei.
10 *
11 * Return the number of items that match the given rule.
12 *
13 * Example 1:
14 *
15 * Input: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"
16 * Output: 1
17 * Explanation: There is only one item matching the given rule, which is ["computer","silver","lenovo"].
18 *
19 * Example 2:
20 *
21 * Input: items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"
22 * Output: 2
23 * Explanation: There are only two items matching the given rule, which are ["phone","blue","pixel"] and ["phone","gold","iphone"]. Note that the item ["computer","silver","phone"] does not match.
24 *
25 * Constraints:
26 *
27 * 1 <= items.length <= 10^4
28 * 1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
29 * ruleKey is equal to either "type", "color", or "name".
30 * All strings consist only of lowercase letters.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/count-items-matching-a-rule/
36// discuss: https://leetcode.com/problems/count-items-matching-a-rule/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn count_matches(items: Vec<Vec<String>>, rule_key: String, rule_value: String) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_1773() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.