forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2180.java
32 lines (29 loc) · 807 Bytes
/
_2180.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.List;
public class _2180 {
public static class Solution1 {
public int countEven(int num) {
int ans = 0;
for (int i = 1; i <= num; i++) {
List<Integer> list = getAllDigits(i);
int sum = 0;
for (int l : list) {
sum += l;
}
if (sum % 2 == 0) {
ans++;
}
}
return ans;
}
private List<Integer> getAllDigits(int num) {
List<Integer> ans = new ArrayList<>();
while (num != 0) {
ans.add(num % 10);
num /= 10;
}
return ans;
}
}
}