P4.3 MissingInteger
Find the smallest positive integer that does not occur in a given sequence.
- P4.3 缺失的整数
寻找在给定的数组中未出现的最小的正整数
编写函数:
def solution(A)
A是由N个整数组成的数组,返回A中未出现的最小的正整数。
例如,
给定A=[1,3,6,4,1,2],函数应该返回5;
给定A=[1,2,3],函数应该返回4;
给定A=[−1、−3],函数应该返回1;
假定:
- N是区间[1,100000]内的整数;
- 数组A的每个元素都是区间[-1000000,1000000]内的整数;
- 解题思路