Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int jumpingOnClouds(int[] c) {
- int index=0,count=0;
- for(int i=0;i<c.length;i++){
- if(index<c.length-2)
- {
- if(c[index]==0){
- if(c[index+1]==0&&c[index+2]==1){
- index=index+1;
- count++;
- }
- else if(c[index+2]==0&&c[index+1]==1){
- index=index+2;
- count++;
- }
- else if(c[index+2]==0&&c[index+1]==0){
- index=index+2;
- count++;
- }
- }
- }
- else if(index<c.length-1){
- if(c[index+1]==0){
- index=index+1;
- count++;
- }
- }
- if(index==c.length-1)break;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement