2022-06-10 23:34:17 +08:00
< 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 > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-06-10 23:34:17 +08:00
< pre >
< strong > Input:< / strong > num = " 1210"
< strong > Output:< / strong > true
< strong > Explanation:< / strong >
num[0] = ' 1' . The digit 0 occurs once in num.
num[1] = ' 2' . The digit 1 occurs twice in num.
num[2] = ' 1' . The digit 2 occurs once in num.
num[3] = ' 0' . The digit 3 occurs zero times in num.
The condition holds true for every index in " 1210" , so return true.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-06-10 23:34:17 +08:00
< pre >
< strong > Input:< / strong > num = " 030"
< strong > Output:< / strong > false
< strong > Explanation:< / strong >
num[0] = ' 0' . The digit 0 should occur zero times, but actually occurs twice in num.
num[1] = ' 3' . The digit 1 should occur three times, but actually occurs zero times in num.
num[2] = ' 0' . The digit 2 occurs zero times in num.
The indices 0 and 1 both violate the condition, so return false.
< / pre >
< p > < / 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 >