-
1523. Count Odd Numbers in an Interval Range python javaLeetCode_Study_Plan/Programming Skills 2022. 9. 19. 20:01
https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/
Count Odd Numbers in an Interval Range - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Python3
def countOdds(self, low: int, high: int) -> int: diff = high - low + 1 if diff % 2 == 1: if low % 2 == 1: return int(diff / 2) + 1 else: return int(diff / 2) else: return int(diff / 2)
Java
class Solution { public int countOdds(int low, int high) { int diff = high - low + 1; if (diff % 2 == 1){ if (low % 2 == 1) { return diff / 2 + 1 ; } else{ return diff / 2; } } else{ return diff/2; } } }
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
976. Largest Perimeter Triangle java (0) 2022.09.19 1281. Subtract the Product and Sum of Digits of an Integer java (0) 2022.09.19 191. Number of 1 Bits java (1) 2022.09.19 1491. Average Salary Excluding the Minimum and Maximum Salary python java (1) 2022.09.19 [Programming Skills I] 시작 그리고 도전 (0) 2022.09.19