2298. Count Integers With Even Digit Sum
My accepted C++ solution to LeetCode problem 2298, Count Integers With Even Digit Sum, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 7.8MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 7.8MB, accepted 2025-12-27.
class Solution {
public:
int countEven(int num) {
int count = 0;
for (int i = 1; i <= num; i++) {
int sum = 0, n = i;
while (n) { sum += n % 10; n /= 10; }
if (sum % 2 == 0) count++;
}
return count;
}
};