/*
* @lc app=leetcode.cn id=2283 lang=typescript
*
* [2283] 判断一个数的数字计数是否等于数位的值
*/
// @lc code=start
function digitCount(num: string): boolean {}
// @lc code=end
function digitCount(num: string): boolean {
const cnt: number[] = []
for (let ch of num) {
const i = Number(ch)
cnt[i] = (cnt[i] ?? 0) + 1
}
for (let i = 0; i < num.length; i++) {
if ((cnt[i] ?? 0) !== Number(num[i])) return false
}
return true
}
test.each([
{ input: { num: '1210' }, output: true },
{ input: { num: '030' }, output: false },
])('input: num = $input.num', ({ input: { num }, output }) => {
expect(digitCount(num)).toEqual(output)
})