-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path41.cpp
More file actions
23 lines (21 loc) · 711 Bytes
/
Copy path41.cpp
File metadata and controls
23 lines (21 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*******************************************************************************
> File Name: 41.cpp
> Author: sillyplus
> Mail: oi_boy@sina.cn
> Created Time: Wed Mar 9 10:53:55 2016
*******************************************************************************/
class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
int n = nums.size();
for (int i = 0; i < n; ++i) {
while (nums[i] >= 1 && nums[i] <= n && nums[i] != nums[nums[i] - 1])
swap(nums[i], nums[nums[i] - 1]);
}
int ret = 1;
for (ret = 1; ret <= n; ++ret)
if (nums[ret-1] != ret)
break;
return ret;
}
};