题目
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
解题思路
(high-low)/2
对于low
和high
四种不同的奇偶性,只有都是偶数的时候不需要+1
代码
class Solution:
def countOdds(self, low: int, high: int) -> int:
return (high - low) // 2 + (low % 2 == 1 or high % 2 == 1)