LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 7.8MB, accepted 2025-12-27.

cpp
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;
    }
};

Source