Easy
Count Odd Numbers in an Interval Range — C++
Full explanation · Time O(1) · Space O(1)
// Time: O(n)
// Space: O(1)
class Solution {
public:
int countOdds(int low, int high) {
return (high + 1) / 2 - ((low - 1) + 1) / 2;
}
};
Full explanation · Time O(1) · Space O(1)
// Time: O(n)
// Space: O(1)
class Solution {
public:
int countOdds(int low, int high) {
return (high + 1) / 2 - ((low - 1) + 1) / 2;
}
};