由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - find the first missing positive number
相关主题
有人同看First Missing Positive 吗?帮俺看一下代码DP+DFS为什么过不了work break II 那个大case : aaaaaaa...
请教一下leetcode gas stationdivide two integers
Surrounded Regions, dfs solution. 过不了online test新题gas station,献丑了,没过一个case,帮看看
lc 上面4 sum的时间复杂度要求多少?C++ Q 103-105
Leetcode: First Missing Positive问一问这个题。
java 基本问题这段代码在leetcode上面跑不了??
哪位大侠帮我看看这个code请大牛review一下这个Insertion Sort List的解法
Leetcode Copy List with Random Pointer Runtime Error?请帖个Median of Two Sorted Arrays的好解法?
相关话题的讨论汇总
话题: int话题: return话题: 交换话题: note
进入JobHunting版参与讨论
1 (共1页)
g***j
发帖数: 1275
1
这个问题的基本思路就是交换,然后把合适的数放在合适的位置
比如 -1,3,1,4
交换之后便成 1,-1,3,4
代码如下
但是我有一个地方想不明白
A[i] != A[A[i] - 1]
这个是什么意思?
为什么不是 A[i] != i+1?
=======================================
int firstMissingPositive(int A[], int n) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if(n == 0) return 1;

for(int i = 0; i < n; i++){
while (A[i] >=1 && A[i] <=n && A[i] != A[A[i] - 1]) {
swap(&A[i], &A[A[i]-1]);
}
}

for(int i = 0; i < n; i++) {
if(A[i] - 1 != i)
return i+1;
}

return n+1;
}
J****3
发帖数: 427
2
Bucket sort 变体哇 对应正确的桶位置
1 (共1页)
进入JobHunting版参与讨论
相关主题
请帖个Median of Two Sorted Arrays的好解法?Leetcode: First Missing Positive
小弟求问LinkedIn那道Deep Iterator的题java 基本问题
m物品n箱子的排法哪位大侠帮我看看这个code
google追加面试。。。Leetcode Copy List with Random Pointer Runtime Error?
有人同看First Missing Positive 吗?帮俺看一下代码DP+DFS为什么过不了work break II 那个大case : aaaaaaa...
请教一下leetcode gas stationdivide two integers
Surrounded Regions, dfs solution. 过不了online test新题gas station,献丑了,没过一个case,帮看看
lc 上面4 sum的时间复杂度要求多少?C++ Q 103-105
相关话题的讨论汇总
话题: int话题: return话题: 交换话题: note