Count Odd Numbers in an Interval Range LeetCode solution in Python

1
class Solution:
2
def countOdds(self, low: int, high: int) -> int:
3
total_nums = high - low
4

5
answer = total_nums // 2
6

7
if low % 2 == 1 and high % 2 == 1:
8
return answer + 1
9

10
if low % 2 == 1:
11
answer = answer + 1
12

13
if high % 2 == 1:
14
answer = answer + 1
15

16
return answer

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0