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 |
Tags
- AI 경진대회
- 프로그래머스
- 프로그래머스 파이썬
- 자연어처리
- ubuntu
- Kaggle
- 더현대서울 맛집
- 파이썬
- ChatGPT
- Baekjoon
- dacon
- Git
- github
- 백준
- hackerrank
- 금융문자분석경진대회
- programmers
- 코로나19
- leetcode
- 편스토랑
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- 데이콘
- 맥북
- SW Expert Academy
- Docker
- 우분투
- gs25
- 편스토랑 우승상품
- PYTHON
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



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |