class Solution(object):
def countOdds(self, low, high): """ (not optimal) count=0
for i in range(low,high+1):
if i%2!=0:
count+=1
return count"""
(optimal solution)
if low%2!=0 or high%2!=0:
return (high-low)/2+1
else:
return ((high-low)/2)
"""
:type low: int
:type high: int
:rtype: int
"""
Comments
Post a Comment