Skip to content

Commit 2c34031

Browse files
solves count odd numbers in interval range
1 parent 3772606 commit 2c34031

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | |
385385
| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | |
386386
| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | |
387-
| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | |
387+
| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | |
388388
| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | |
389389
| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | |
390390
| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | |
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class CountOddNumbersInIntervalRange {
2+
public int countOdds(int low, int high) {
3+
final int count = high - low + 1;
4+
if ((count & 1) == 0) return count / 2;
5+
return count / 2 + (low & 1);
6+
}
7+
}

0 commit comments

Comments
 (0)