파비의 매일매일 공부기록

2023.03.06 Today's Challenge 본문

Problem Solving/LeetCode

2023.03.06 Today's Challenge

fabichoi 2023. 3. 6. 23:45

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