Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ee8b5a

Browse files
committedMay 13, 2023
solves #2180: Count Integers With Even Digit Sum in java
1 parent d7fde37 commit 0ee8b5a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@
707707
| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | |
708708
| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | |
709709
| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | |
710-
| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | |
710+
| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
711711
| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | |
712712
| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | |
713713
| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://leetcode.com/problems/count-integers-with-even-digit-sum
2+
// T: O(1)
3+
// S: O(1)
4+
5+
public class CountIntegersWithEvenDigitSum {
6+
public int countEven(int num) {
7+
final int group = num / 10;
8+
return 5 * group - 1 + (num % 10 + 1 + series(group)) / 2;
9+
}
10+
11+
private int series(int group) {
12+
return (group % 10 + (group % 100) / 10 + (group % 1000) / 100 + 1) % 2;
13+
}
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.