We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d83108 commit 66ac2aeCopy full SHA for 66ac2ae
Easy/Count Odd Numbers in an Interval Range.java
@@ -1,5 +1,5 @@
1
class Solution {
2
public int countOdds(int low, int high) {
3
- return (high + 1) / 2 - low / 2;
+ return (high - low) / 2 + (low % 2 != 0 || high % 2 != 0 ? 1 : 0);
4
}
5
0 commit comments