Count Odd Numbers in an Interval Range

easy math

Problem

Given two non-negative integers low and high, return the count of odd numbers between low and high (inclusive).

Inputlow = 3, high = 7
Output3
The odd numbers between 3 and 7 are 3, 5, 7.

def count_odds(low, high):
    return (high + 1) // 2 - low // 2
function countOdds(low, high) {
  return ((high + 1) >> 1) - (low >> 1);
}
class Solution {
    public int countOdds(int low, int high) {
        return ((high + 1) / 2) - (low / 2);
    }
}
int countOdds(int low, int high) {
    return ((high + 1) / 2) - (low / 2);
}
Time: O(1) Space: O(1)