Leetcode Note: Go - Check if Number Has Equal Digit Count and Digit Value

Check if Number Has Equal Digit Count and Digit Value - LeetCode
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/

  • Go 言語で取り組んだメモ

回答

✅ Easy Go Solution - Check if Number Has Equal Digit Count and Digit Value - LeetCode
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/solutions/3395513/easy-go-solution/

func digitCount(num string) bool {
        var counters [10]int

        for i := 0; i < len(num); i++ {
                val := num[i]
                counters[int(val-'0')]++
        }

        isMatch := true
        for i := 0; i < len(num); i++ {
                val := num[i]
                if counters[i] != int(val-'0') {
                        isMatch = false
                        break
                }
        }

        return isMatch
}