You are viewing a single comment's thread. Return to all comments →
Java 8 solution;
i didnt try to count zeros at c list. i try count 1 at c.list i add to index of "1" from c list to new arraylist. and substraction between two index.
List<Integer> indexofOnes= new ArrayList<>(); int lastIndexOfOnes=0; for(int i=0; i<c.size();i++){ if(c.get(i)==1){ indexofOnes.add(i+1); lastIndexOfOnes=i+1; } } int jump=0; int beforeJump=0; int count =0; for(Integer item: indexofOnes){ jump=(item-beforeJump+1)/2; if(item-beforeJump==1 || item-beforeJump==0){ jump++; } beforeJump=item; count=count+jump; } int lastJump=(c.size()-lastIndexOfOnes)/2; int endOfJump=count+lastJump; return endOfJump; }
Seems like cookies are disabled on this browser, please enable them to open this website
Jumping on the Clouds
You are viewing a single comment's thread. Return to all comments →
Java 8 solution;
i didnt try to count zeros at c list. i try count 1 at c.list i add to index of "1" from c list to new arraylist. and substraction between two index.