Given two non-negative integers low
and high
. Return the count of odd numbers between low
and high
(inclusive).
Example
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Solution
/**
* @param {number} l
* @param {number} h
* @return {number}
*/
var countOdds = function (l, h) {
// If the lower bound is even, increment it
return Math.floor((h + 1) / 2) - Math.floor(l / 2);
};