java.lang.Object
g1701_1800.s1773_count_items_matching_a_rule.Solution

public class Solution extends Object
1773 - Count Items Matching a Rule.<p>Easy</p> <p>You are given an array <code>items</code>, where each <code>items[i] = [type<sub>i</sub>, color<sub>i</sub>, name<sub>i</sub>]</code> describes the type, color, and name of the <code>i<sup>th</sup></code> item. You are also given a rule represented by two strings, <code>ruleKey</code> and <code>ruleValue</code>.</p> <p>The <code>i<sup>th</sup></code> item is said to match the rule if <strong>one</strong> of the following is true:</p> <ul> <li><code>ruleKey == &quot;type&quot;</code> and <code>ruleValue == type<sub>i</sub></code>.</li> <li><code>ruleKey == &quot;color&quot;</code> and <code>ruleValue == color<sub>i</sub></code>.</li> <li><code>ruleKey == &quot;name&quot;</code> and <code>ruleValue == name<sub>i</sub></code>.</li> </ul> <p>Return <em>the number of items that match the given rule</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> items = [[&ldquo;phone&rdquo;,&ldquo;blue&rdquo;,&ldquo;pixel&rdquo;],[&ldquo;computer&rdquo;,&ldquo;silver&rdquo;,&ldquo;lenovo&rdquo;],[&ldquo;phone&rdquo;,&ldquo;gold&rdquo;,&ldquo;iphone&rdquo;]], ruleKey = &ldquo;color&rdquo;, ruleValue = &ldquo;silver&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> There is only one item matching the given rule, which is [&ldquo;computer&rdquo;,&ldquo;silver&rdquo;,&ldquo;lenovo&rdquo;].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> items = [[&ldquo;phone&rdquo;,&ldquo;blue&rdquo;,&ldquo;pixel&rdquo;],[&ldquo;computer&rdquo;,&ldquo;silver&rdquo;,&ldquo;phone&rdquo;],[&ldquo;phone&rdquo;,&ldquo;gold&rdquo;,&ldquo;iphone&rdquo;]], ruleKey = &ldquo;type&rdquo;, ruleValue = &ldquo;phone&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> There are only two items matching the given rule, which are [&ldquo;phone&rdquo;,&ldquo;blue&rdquo;,&ldquo;pixel&rdquo;] and [&ldquo;phone&rdquo;,&ldquo;gold&rdquo;,&ldquo;iphone&rdquo;]. Note that the item [&ldquo;computer&rdquo;,&ldquo;silver&rdquo;,&ldquo;phone&rdquo;] does not match.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= items.length <= 10<sup>4</sup></code></li> <li><code>1 <= type<sub>i</sub>.length, color<sub>i</sub>.length, name<sub>i</sub>.length, ruleValue.length <= 10</code></li> <li><code>ruleKey</code> is equal to either <code>&quot;type&quot;</code>, <code>&quot;color&quot;</code>, or <code>&quot;name&quot;</code>.</li> <li>All strings consist only of lowercase letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details