```
public boolean canCross(int[] stones) {
int n = stones.length;
// DP tracks the max units of last jump to reach each stone
int[] dp = new int[n];
for (int i = 0; i < n; i++) {
// Skip if no previous jumps can reach this stone
if (i > 0 && dp[i] == 0) continue;
// Greedy try to jump forward as far as possible
for (int j = i + 1; j < n; j++) {
int gap = stones[j] - stones[i];
if (gap > dp[i] + 1) break; // Too far to reach
if (gap == dp[i] - 1 || gap == dp[i] || gap == dp[i] + 1) {
dp[j] = Math.max(gap, dp[j]); // Update DP if a stone is reachable
}
}
}
return dp[n - 1] > 0;
}
```

]]>```
public boolean canCross(int[] stones) {
int n = stones.length;
// DP tracks the max units of last jump to reach each stone
int[] dp = new int[n];
for (int i = 0; i < n; i++) {
// Skip if no previous jumps can reach this stone
if (i > 0 && dp[i] == 0) continue;
// Greedy try to jump forward as far as possible
for (int j = i + 1; j < n; j++) {
int gap = stones[j] - stones[i];
if (gap > dp[i] + 1) break; // Too far to reach
if (gap == dp[i] - 1 || gap == dp[i] || gap == dp[i] + 1) {
dp[j] = Math.max(gap, dp[j]); // Update DP if a stone is reachable
}
}
}
return dp[n - 1] > 0;
}
```

]]>it should be true, yours return false

]]>[0,1,3,6,10, 13, 15, 18]

Nice catch! Your test case should be added by leetcode. I'll fix my bug.

]]>