Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean getToZero(List<Integer> arr, int startingIdx) {
- int currentVal = arr.get(startingIdx);
- if(currentVal==0){
- return true;
- } else if (currentVal == null){
- return false;
- } else {
- arr.set(startingIdx, null);
- int topVal = startingIdx + arr.get(startingIdx);
- int bottomVal = startingIdx - arr.get(startingIdx);
- if (bottomVal >= 0) {
- boolean foundOnBottom = getToZero(arr, bottomVal);
- }
- if (topVal <= arr.size()){
- boolean foundOnTop = getToZero(arr, topVal);
- }
- return foundOnBottom==true || foundOnTop == true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement