什么都想学,但是时间就像海绵里的水,每次挤出来的都是那么一点。。。
话虽如此,还是要向前看,向前跑的!
题目:
给定一个未排序的整数数组,找出其中没有出现的最小的正整数。
示例 1:
输入: [1,2,0]
输出: 3
示例 2:
输入: [3,4,-1,1]
输出: 2
示例 3:
输入: [7,8,9,11,12]
输出: 1
说明:
你的算法的时间复杂度应为O(n),并且只能使用常数级别的空间。
咬着指头思索一下,唔。。。。
唔。。。。
想法:
这个数组的长度是从0到n,要求的值是1-n,那么做某个处理之后,数组的长度 + 1,不就是要求的值吗
试试:
就用python写吧,语法简介,顺便学习一下python的语法,
上代码:
ist = []
def cal(index):
length = len(list)
if index >= length:
return
b = int(list[index])
if b > length:
list.remove(str(b))
return cal(index)
elif b <= 0:
list.remove(str(b))
return cal(index)
else:
if b < index + 1:
list.remove(str(b))
return cal(index)
elif b =&#