일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- English
- 만화도
- 리얼 클래스
- Problem Solving
- 괜찮음
- 뭐든
- 프로젝트
- 30분
- 스탭퍼
- 화상영어
- 10분
- 매일
- Daily Challenge
- 영어원서읽기
- 영어공부
- 잡생각
- 개발자
- 3줄정리
- 읽기
- 운동
- realclass
- Writing
- 미드시청
- 사이드
- 쓰릴오브파이트
- leetcode
- FIT XR
- 월간
- 파비최
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.21 Today's Challenge 본문
https://leetcode.com/problems/single-element-in-a-sorted-array/
Single Element in a Sorted Array - LeetCode
Can you solve this real interview question? Single Element in a Sorted Array - You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element
leetcode.com
어제에 이은 바이너리 서치 문제
class Solution:
def singleNonDuplicate(self, nums: List[int]) -> int:
l, r = 0, len(nums) // 2
ans = -1
while l <= r:
mid = (l+r) // 2
idx = mid * 2
if idx + 1 >= len(nums) or nums[idx] != nums[idx+1]:
r = mid-1
ans = nums[idx]
else:
l = mid + 1
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.23 Today's Challenge (0) | 2023.02.23 |
---|---|
2023.02.22 Today's Challenge (0) | 2023.02.22 |
2023.02.20 Today's Challenge (0) | 2023.02.20 |
2023.02.19 Today's Challenge (0) | 2023.02.19 |
2023.02.18 Today's Challenge (0) | 2023.02.18 |
Comments