8000 * Done with "2180. Count Integers With Even Digit Sum" · garciparedes/leetcode@9050e4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9050e4d

Browse files
committed
* Done with "2180. Count Integers With Even Digit Sum"
1 parent 3750226 commit 9050e4d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def countEven(self, num: int) -> int:
3+
ans = 0
4+
for i in range(1, num + 1):
5+
if self._digit_sum(i) % 2 == 0:
6+
ans += 1
7+
return ans
8+
9+
def _digit_sum(self, num: int) -> int:
10+
ans = 0
11+
while num > 0:
12+
ans += num % 10
13+
num //= 10
14+
return ans

0 commit comments

Comments
 (0)
0