Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 편스토랑 우승상품
- 코로나19
- leetcode
- SW Expert Academy
- 캐치카페
- Docker
- ChatGPT
- dacon
- 금융문자분석경진대회
- 백준
- 편스토랑
- AI 경진대회
- 파이썬
- 우분투
- 더현대서울 맛집
- ubuntu
- hackerrank
- github
- Baekjoon
- programmers
- Kaggle
- Git
- PYTHON
- 자연어처리
- 맥북
- Real or Not? NLP with Disaster Tweets
- gs25
- 프로그래머스
- 프로그래머스 파이썬
- 데이콘
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1523. Count Odd Numbers in an Interval Range (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 1523. Count Odd Numbers in an Interval Range (Python)
솜씨좋은장씨 2020. 12. 28. 00:13728x90
반응형
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
Example 1:
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Example 2:
Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9].
Constraints:
- 0 <= low <= high <= 10^9
Solution
class Solution:
def countOdds(self, low: int, high: int) -> int:
answer = 0
if high-low == 1:
answer = 1
elif low % 2 == 1 and high % 2 == 1:
answer = (high - low + 1) // 2 + 1
elif low % 2 == 0 and high % 2 == 0:
answer = (high - low + 1) // 2
elif (low % 2 == 0 and high % 2 == 1) or (low % 2 == 1 and high % 2 == 0):
answer = (high - low + 1) // 2
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1295. Find Numbers with Even Number of Digits (Python) (0) | 2020.12.30 |
---|---|
[leetCode] 1491. Average Salary Excluding the Minimum and Maximum Salary (Python) (0) | 2020.12.29 |
[leetCode] 1539. Kth Missing Positive Number (Python) (0) | 2020.12.27 |
[leetCode] 92. Reverse Linked List II (Python) (0) | 2020.12.26 |
[Programmers] 최고의 집합 (Python) (0) | 2020.12.22 |
Comments