java.lang.Object
g2201_2300.s2283_check_if_number_has_equal_digit_count_and_digit_value.Solution

public class Solution extends Object
2283 - Check if Number Has Equal Digit Count and Digit Value.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> string <code>num</code> of length <code>n</code> consisting of digits.</p> <p>Return <code>true</code> <em>if for <strong>every</strong> index</em> <code>i</code> <em>in the range</em> <code>0 <= i < n</code><em>, the digit</em> <code>i</code> <em>occurs</em> <code>num[i]</code> <em>times in</em> <code>num</code><em>, otherwise return</em> <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = &ldquo;1210&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>num[0] = &lsquo;1&rsquo;. The digit 0 occurs once in num.</p> <p>num[1] = &lsquo;2&rsquo;. The digit 1 occurs twice in num.</p> <p>num[2] = &lsquo;1&rsquo;. The digit 2 occurs once in num.</p> <p>num[3] = &lsquo;0&rsquo;. The digit 3 occurs zero times in num.</p> <p>The condition holds true for every index in &ldquo;1210&rdquo;, so return true.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = &ldquo;030&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>num[0] = &lsquo;0&rsquo;. The digit 0 should occur zero times, but actually occurs twice in num.</p> <p>num[1] = &lsquo;3&rsquo;. The digit 1 should occur three times, but actually occurs zero times in num.</p> <p>num[2] = &lsquo;0&rsquo;. The digit 2 occurs zero times in num.</p> <p>The indices 0 and 1 both violate the condition, so return false.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == num.length</code></li> <li><code>1 <= n <= 10</code></li> <li><code>num</code> consists of digits.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • digitCount

      public boolean digitCount(String num)