Skip to content

Commit c118389

Browse files
author
Steve Sun
committed
add 2180
1 parent 3576b52 commit c118389

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|---------------|--------|-------------|-------------
11+
| 2180 |[Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2180.java) ||Easy||
1112
| 2177 |[Find Three Consecutive Integers That Sum to a Given Number](https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2177.java) ||Medium||
1213
| 2176 |[Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2176.java) ||Easy||
1314
| 2169 |[Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2169.java) ||Easy||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2180 {
7+
public static class Solution1 {
8+
public int countEven(int num) {
9+
int ans = 0;
10+
for (int i = 1; i <= num; i++) {
11+
List<Integer> list = getAllDigits(i);
12+
int sum = 0;
13+
for (int l : list) {
14+
sum += l;
15+
}
16+
if (sum % 2 == 0) {
17+
ans++;
18+
}
19+
}
20+
return ans;
21+
}
22+
23+
private List<Integer> getAllDigits(int num) {
24+
List<Integer> ans = new ArrayList<>();
25+
while (num != 0) {
26+
ans.add(num % 10);
27+
num /= 10;
28+
}
29+
return ans;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)