由买买提看人间百态

topics

全部话题 - 话题: canreach
(共0页)
s****0
发帖数: 117
1
来自主题: JobHunting版 - leetcode jump game2
先贴我的,再看大家的。
public class Solution {
public int jump(int[] jmp) {
int n = jmp.length;
int canReach[] = new int[n];
for (int i = 1; i < n; i++) {
canReach[i] = Integer.MAX_VALUE;
}
canReach[0] = 0;
int head = 0;
for (int i = 0; i < n; i++) {
if (canReach[i] > n)
continue;
for (int j = Math.max(i, head) + 1; (j <= i + jmp[i]) && (j < n)
; j++) {
canReach[j] = Math.min(canR... 阅读全帖
i**********e
发帖数: 1145
2
来自主题: JobHunting版 - Google on campus 面经
这个解法不对,有 bug.
test case:
{22,11,33,33,44,22,11}
t = 22,
output=
{11 33 33 44 44 22 22}
expected=
{11 33 33 44 11 22 22}
第一题的解:
void shiftArrayEqualsTBack(int num[], int n, int t) {
int total = 0;
for (int i = 0; i < n; i++) {
if (num[i] == t)
total++;
else
num[i-total] = num[i];
}
for (int i = n-total; i < n; i++) {
num[i] = t;
}
}
第二题的解:
const int X_MAX = 4;
const int Y_MAX = 4;
bool validLocation(int x, int y) {
if (x <= -1 || x >= X_MAX || y <= -1 || y >= Y... 阅读全帖
(共0页)