일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 뭐든
- 잡생각
- 화상영어
- 괜찮음
- 만화도
- 프로젝트
- Writing
- 링피트
- 읽기
- 3줄정리
- 미드시청
- 매일
- English
- Problem Solving
- Daily Challenge
- 영어공부
- 리얼 클래스
- 스탭퍼
- 10분
- 쓰릴오브파이트
- 파비최
- 월간
- 운동
- 사이드
- FIT XR
- 30분
- 개발자
- 영어원서읽기
- realclass
- leetcode
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.06 Today's Challenge 본문
https://leetcode.com/problems/kth-missing-positive-number/
Kth Missing Positive Number - LeetCode
Can you solve this real interview question? Kth Missing Positive Number - Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the kth positive integer that is missing from this array. Example 1: Input:
leetcode.com
조금 허접하지만 내손으로 풀어봄.
이분탐색으로 찾는 방법도 있었다.
class Solution:
def findKthPositive(self, arr: List[int], k: int) -> int:
idx, res = 0, []
for i in range(1, 2001):
if i != arr[idx]:
res.append(i)
continue
if idx < len(arr) - 1:
idx += 1
return res[k-1]
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.08 Today's Challenge (0) | 2023.03.08 |
---|---|
2023.03.07 Today's Challenge (0) | 2023.03.07 |
2023.03.05 Today's Challenge (0) | 2023.03.05 |
2023.03.04 Today's Challenge (0) | 2023.03.04 |
2023.03.03 Today's Challenge (0) | 2023.03.03 |
Comments