Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
 
Example 1:
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Example 2:
Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9].
 
Constraints:

0 <= low <= high <= 10^9

Difficulty: introductory

Starter code:

class Solution:
    def countOdds(self, low: int, high: int) -> int:
        

Solutions:
class Solution:
    def countOdds(self, low: int, high: int) -> int:
        if low %2 != 0:
            low -=1
        if high %2 != 0:
            high +=1 
            
        return (high-low) // 2

class Solution:
    def countOdds(self, low: int, high: int) -> int:
        return (high-high//2)-(low-low//2)+low%2


class Solution:
    def countOdds(self, low: int, high: int) -> int:
        return ((high + 1)>>1) - (low>>1)

class Solution:
    def countOdds(self, low: int, high: int) -> int:
        c = 0
        if low < 0 or high > 10**9:
            return
        else:
            if (low%2 != 0 and high%2 !=0):
                return int((high-low)/2)+1
            elif ((low%2 == 0 and high%2 != 0) or (low%2 != 0 and high%2 == 0)):
                return int((high-low)/2)+1
            else:
                return int((high-low)/2)


class Solution:
    def countOdds(self, low: int, high: int) -> int:
        c = 0
        if low < 0 or high > 10**9:
            return
        else:
            if (low%2 == 0 and high%2 ==0):
                return int((high-low)/2)
            else:
                return int((high-low)/2)+1                


class Solution:
    def countOdds(self, low: int, high: int) -> int:
      
        ## O(1) With Math
        odd_lowerbound, odd_upperbound = -1, -1
        
        # compute smallest odd number in range
        if low % 2 == 1:
            odd_lowerbound = low
        else:
            odd_lowerbound = low + 1
        
        # compute largest odd number in range
        if high % 2 == 1:
            odd_upperbound = high
        else:
            odd_upperbound = high - 1
            
        
        # compute the number of odd numbers in range
        return (odd_upperbound - odd_lowerbound) // 2 + 1
    


class Solution:
    def countOdds(self, low: int, high: int) -> int:
        return (high + 1) // 2 - (low //2)

class Solution:
    def countOdds(self, low: int, high: int) -> int:
        return (high - low + 1) // 2 + (high % 2 and low % 2);


class Solution:
    def countOdds(self, lo, hi):
        return (hi+1)//2 - lo//2