728x90
https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/
class Solution:
def countOdds(self, low: int, high: int) -> int:
count = (high - low) // 2
if low % 2 == 0 and high % 2 == 0:
return count
else:
return count + 1
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 1295. Find Numbers with Even Number of Digits (0) | 2023.08.19 |
---|---|
[Leetcode] 485. Max Consecutive Ones (0) | 2023.08.19 |
[Leetcode] 2278. Percentage of Letter in String (0) | 2023.08.16 |
[Leetcode] 175. Combine Two Tables (0) | 2023.08.16 |
[Leetcode] 2042. Check if Numbers Are Ascending in a Sentence (0) | 2023.08.14 |