Leetcode Note: Go - Count Integers With Even Digit Sum
Count Integers With Even Digit Sum - LeetCode
https://leetcode.com/problems/count-integers-with-even-digit-sum/
- Go 言語で取り組んだメモ
回答
golang solution 0ms 100% - Count Integers With Even Digit Sum - LeetCode
https://leetcode.com/problems/count-integers-with-even-digit-sum/solutions/2109839/golang-solution-0ms-100/
func countEven(num int) int {
ans := 0
for i := 1; i <= num; i++ {
tmp := i
s := 0
for tmp > 0 {
s += tmp % 10
tmp /= 10
}
if s % 2 == 0 {
ans++
}
}
return ans
}