Class Solution
-
- All Implemented Interfaces:
public final class Solution2283 - Check if Number Has Equal Digit Count and Digit Value\.
Easy
You are given a 0-indexed string
numof lengthnconsisting of digits.Return
trueif for every indexiin the range0 <= i < n, the digitioccursnum[i]times innum, otherwise returnfalse.Example 1:
Input: num = "1210"
Output: true
Explanation:
num0 = '1'. The digit 0 occurs once in num.
num1 = '2'. The digit 1 occurs twice in num.
num2 = '1'. The digit 2 occurs once in num.
num3 = '0'. The digit 3 occurs zero times in num.
The condition holds true for every index in "1210", so return true.
Example 2:
Input: num = "030"
Output: false
Explanation:
num0 = '0'. The digit 0 should occur zero times, but actually occurs twice in num.
num1 = '3'. The digit 1 should occur three times, but actually occurs zero times in num.
num2 = '0'. The digit 2 occurs zero times in num.
The indices 0 and 1 both violate the condition, so return false.
Constraints:
n == num.length1 <= n <= 10numconsists of digits.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleandigitCount(String num)-
-
Method Detail
-
digitCount
final Boolean digitCount(String num)
-
-
-
-