Skip to content

Commit 8a752f6

Browse files
committed
Time: 42 ms (21.22%), Space: 17.7 MB (49.37%) - LeetHub
1 parent 122f086 commit 8a752f6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def countOdds(self, low: int, high: int) -> int:
3+
if low % 2 == 0 and high % 2 == 0:
4+
return (high - low) // 2
5+
else:
6+
return (high - low) // 2 + 1
7+
8+
'''
9+
even even
10+
10 16 -> 11 13 15 -> (16 - 10) // 2
11+
12+
odd even
13+
11 16 -> 11 13 15 -> (16 - 11) // 2 + 1
14+
15+
odd odd
16+
11 15 -> 11 13 15 -> (15 - 11) // 2 + 1
17+
18+
even odd
19+
10 15 -> 11 13 15 -> (15 - 10) // 2 + 1
20+
'''
21+
22+
23+
low = 3
24+
high = 7
25+
print(Solution().countOdds(low, high))
26+
low = 8
27+
high = 10
28+
print(Solution().countOdds(low, high))

0 commit comments

Comments
 (0)