본문 바로가기

IT/코딩테스트

[Leetcode] 1523. Count Odd Numbers in an Interval Range

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