Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
Your algorithm should run in O(n) time and uses constant space.
本文介绍了一种在未排序整数数组中找到第一个缺失正整数的方法,该算法需在O(n)时间内运行并使用常数空间。通过将数组本身作为桶来标记已存在的数字,从而避免使用额外空间。
Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
Your algorithm should run in O(n) time and uses constant space.
758
730
730

被折叠的 条评论
为什么被折叠?