题目
PS:这题居然是困难,
思路
还是hash
这次hash表用列表来做的
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
hashtable = [0] * (len(nums)+2) # +2 防止hash表全满输出None
for i in range(len(nums)):
if nums[i] < 0 or nums[i] > len(nums):
continue
else:
hashtable[nums[i]] = 1
for i in range(1, len(hashtable)+1): # 正整数 > 0
#
if hashtable[i] == 0:
return i # 返回key
链接
https://leetcode.cn/problems/first-missing-positive/description/?envType=study-plan-v2&envId=bytedance-2023-spring-sprint