1.无重复数组,当数组中不缺少任何元素时,数组中最大的正整数max_num<=len(nums);
2.从1遍历查找,返回不在哈希表的第一个正整数;
3.考虑极限情况:nums=[1,2...,max_num],最小正整数即为max_num+1,因此遍历到len(nums)+1(包含)。nums=[],最小整数为1,因此从1开始遍历
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param nums int整型一维数组
# @return int整型
#
class Solution:
def minNumberDisappeared(self , nums: List[int]) -> int:
# write code here
n = len(nums)
hashmap = dict(zip(nums, [True]*n))
for i in range(1,n+2):
if i not in hashmap:
return i

京公网安备 11010502036488号