Problem: 41. 缺失的第一个正数
哈希
时间复杂度:
添加时间复杂度, 示例: O ( n ) O(n) O(n)
空间复杂度:
添加空间复杂度, 示例: O ( n ) O(n) O(n)
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
length = len(nums)
hashTable = collections.defaultdict(int)
for x in nums:
hashTable[x] += 1
for i in range(1, length + 5):
if i not in hashTable:
return i