// 2283. Check if Number Has Equal Digit Count and Digit Value
class Solution {
public boolean digitCount(String num) {
for (int i = 0; i < num.length(); ++i) {
int count = 0;
for (int j = 0; j < num.length(); ++j) {
if (num.charAt(j) - 48 == i) ++count;
}
if (num.charAt(i) - 48 != count) return false;
}
return true;
}
}
学习笔记: 这是一道简单题,看一下每一位的出现次数对不对,不对就提前返回。