这个效率应该也还可以。
来源:5-8 缺失的第一个正数(1)

weixin_慕仔4426869
2019-07-13
export default (arr) => {
let max = Math.max.apply(Math, arr)
let min = Math.min.apply(Math, arr)
if (min >= 2) {
return 1
}
if ((min === 0 || min === 1) && ((max - min) === arr.length - 1)) {
return max + 1
}
let nextOne = null
let res
for (let item of arr) {
if (nextOne && nextOne > 0 && nextOne !== item) {
res = Math.min(nextOne, res)
}
nextOne = item + 1
}
res = res ? Math.min(nextOne, res) : nextOne
return res
}
写回答
1回答
-
快乐动起来呀
2019-07-14
试下 [-5] 这个输入,输出不对,再考虑下边界
00
相似问题
老师这样的思路效率如何呢?
回答 2
感觉这样也可以的,效率怎么样?
回答 2
改了个LeetCode通过的,但效率好低
回答 1
老师查找用堆和平衡2叉树哪个效率高
回答 1
在力扣上测试通过了提交的时候出错
回答 1