leetcode：41. First Missing Positive (Java)

First Missing Positive

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.

public class Solution {
public int firstMissingPositive(int[] nums) {
int l = nums.length;
int swap;
for (int i = 0; i < l;) {
swap = nums[i++];
while (swap > 0 && swap <= l && swap != nums[swap - 1]) {
int tmp = nums[swap - 1];
nums[swap - 1] = swap;
swap = tmp;
}
}
for (int i = 0; i < l;) {
if (nums[i] != ++i) {
return i;
}
}
return l + 1;
}
}

[LeetCode41] First Missing Positive

Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0...
• sbitswc
• 2014年06月17日 23:51
• 2434

[Leetcode] 41. First Missing Positive

41. First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.F...

LeetCode --- 41. First Missing Positive

• makuiyu
• 2015年02月08日 23:49
• 955

[leetcode-41]First Missing Positive(java)

• zdavb
• 2015年07月10日 22:18
• 475

[LeetCode - 桶排序] 41. First Missing Positive

1 问题 Given an unsorted integer array, find the first missing positive integer. For example, ...

LeetCode 41. First Missing Positive

1. 题目要求 Given an unsorted integer array, find the first missing positive integer. For example...

[leetcode] 41.First Missing Positive

举报原因： 您举报文章：leetcode：41. First Missing Positive (Java) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)