| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 월간
- 만화도
- 10분
- realclass
- 화상영어
- Writing
- 3줄정리
- 괜찮음
- leetcode
- 쓰릴오브파이트
- 영어원서읽기
- 30분
- 리얼 클래스
- 미드시청
- 잡생각
- 사이드
- 읽기
- 매일
- FIT XR
- Problem Solving
- 스탭퍼
- 개발자
- 운동
- English
- 뭐든
- Daily Challenge
- 영어공부
- 프로젝트
- 링피트
- 파비최
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.13 Today's Challenge 본문
https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/
Count Odd Numbers in an Interval Range - LeetCode
Can you solve this real interview question? Count Odd Numbers in an Interval Range - 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 Explanati
leetcode.com
어거지로 풀긴 했는데, 좀 더 엘레강스한 소스 구성이었으면 좋았을 것 같다.
class Solution:
def countOdds(self, low: int, high: int) -> int:
flag = 0
if low % 2 == 0:
low -= 1
else:
flag = 1
if high % 2 == 0:
high -= 1
return ((high+1)//2 - (low+1)//2) + flag반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.02.15 Today's Challenge (0) | 2023.02.15 |
|---|---|
| 2023.02.14 Today's Challenge (0) | 2023.02.14 |
| 2023.02.12 Today's Challenge (0) | 2023.02.12 |
| 2023.02.11 Today's Challenge (0) | 2023.02.11 |
| 2023.02.10 Today's Challenge (0) | 2023.02.10 |
Comments