[LeetCode][Python3] 41. First Missing Positive
2019. 4. 23. 00:38 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/first-missing-positive/
My Solution :
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
i = 0
while i < len(nums):
if (0 < nums[i] <= len(nums) and
nums[i] != nums[nums[i]-1]):
nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1]
i -= 1
i += 1
i = 0
while i < len(nums):
if nums[i] != i+1:
return i+1
i += 1
return i+1
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 5. Longest Palindromic Substring (0) | 2019.04.30 |
---|---|
[LeetCode][Python3] 140. Word Break II (0) | 2019.04.25 |
[LeetCode][Python3] 50. Pow(x, n) (0) | 2019.04.24 |
[LeetCode][Python3] 212. Word Search II (0) | 2019.04.24 |
[LeetCode][Python3] 152. Maximum Product Subarray (0) | 2019.04.22 |
[LeetCode][Python3] 124. Binary Tree Maximum Path Sum (0) | 2019.04.20 |
[LeetCode][Python3] 322. Coin Change (0) | 2019.04.20 |
[LeetCode][Python3] 54. Spiral Matrix (0) | 2019.04.18 |
최근에 달린 댓글 최근에 달린 댓글