What's the problem with my code?

Q.https://leetcode.com/problems/frog-jump/

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;

}
}

hi @v13verma
I take doubts only in C++.
U can refer this code -->

public boolean canCross(int[] stones) {
        Map<Integer, Set<Integer>> dp = new HashMap();
        
        for(int val: stones) dp.put(val, new HashSet());
        dp.get(stones[0]).add(1);
        
        for(int val: stones){
            for(int jump: dp.get(val)){
                if(jump!= 0 && dp.containsKey(val+jump)){
                    dp.get(val+jump).add(jump-1);
                    dp.get(val+jump).add(jump);
                    dp.get(val+jump).add(jump+1);
                }
            }
        }
        
        return !dp.get(stones[stones.length-1]).isEmpty();
    }

Whom to ask for JAVA doubts ?

Reopen a new doubt… some other Java TA will pick up ur doubt…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.