Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public boolean getToZero(List<Integer> arr, int startingIdx) {
  2. int currentVal = arr.get(startingIdx);
  3. if(currentVal==0){
  4. return true;
  5. } else if (currentVal == null){
  6. return false;
  7. } else {
  8. arr.set(startingIdx, null);
  9. int topVal = startingIdx + arr.get(startingIdx);
  10. int bottomVal = startingIdx - arr.get(startingIdx);
  11. if (bottomVal >= 0) {
  12. boolean foundOnBottom = getToZero(arr, bottomVal);
  13. }
  14. if (topVal <= arr.size()){
  15. boolean foundOnTop = getToZero(arr, topVal);
  16. }
  17.  
  18. return foundOnBottom==true || foundOnTop == true;
  19. }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement