Skip to content

Commit 3a9435b

Browse files
committed
Time: 0 ms (100%), Space: 7.3 MB (75%) - LeetHub
1 parent b77e6ad commit 3a9435b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int countEven(int num) {
4+
int ans = 0;
5+
for (int i = 1; i <= num; i++) {
6+
ans += (digSum(i) % 2 == 0);
7+
}
8+
return ans;
9+
}
10+
int digSum(int n) {
11+
int sum = 0;
12+
while (n) {
13+
sum += (n % 10);
14+
n /= 10;
15+
}
16+
return sum;
17+
}
18+
};

0 commit comments

Comments
 (0)