Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. static int jumpingOnClouds(int[] c) {
  2.  
  3.  
  4. int index=0,count=0;
  5. for(int i=0;i<c.length;i++){
  6.  
  7.  
  8. if(index<c.length-2)
  9. {
  10. if(c[index]==0){
  11. if(c[index+1]==0&&c[index+2]==1){
  12. index=index+1;
  13. count++;
  14. }
  15. else if(c[index+2]==0&&c[index+1]==1){
  16. index=index+2;
  17. count++;
  18. }
  19. else if(c[index+2]==0&&c[index+1]==0){
  20. index=index+2;
  21. count++;
  22. }
  23. }
  24. }
  25. else if(index<c.length-1){
  26. if(c[index+1]==0){
  27. index=index+1;
  28. count++;
  29. }
  30.  
  31. }
  32.  
  33.  
  34. if(index==c.length-1)break;
  35.  
  36.  
  37. }
  38.  
  39. return count;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement