Count Odd Numbers in an Interval Range LeetCode solution in C++

1
class Solution {
2
public:
3
int countOdds(int low, int high) {
4
if (low % 2 == 0 && high % 2 == 0) {
5
return (high - low) / 2;
6
} else {
7
return (high - low) / 2 + 1;
8
}
9
}
10
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0