Input: stones = [0,1,3,5,6,8,12,17] Output: true. In the given example how is it able to jump from 8 to 12, while his last jump was only 2 units.
class Solution {
public boolean canCross(int[] stones) {
int count=0;
for(int i=2;i<stones.length;i++) {
int k=stones[i-1]-stones[i-2];
if(stones[i]==stones[i-1]+k)continue;
else if(stones[i]==stones[i-1]+k-1)continue;
else if(stones[i]==stones[i-1]+k+1)continue;
else {
count++;
break;
}
}
if(count==1)return false;
return true;
}
}