Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean isWay(int[] arr)
- {
- return isWay(arr, 0);
- }
- private static boolean isWay(int[] arr, int i)
- {
- final int VISITED=0;
- if(i<0||i>=arr.length)//if got out from the array limits
- return false;
- if(i==arr.length-1)//if got to the end of the array
- return true;
- if(arr[i]==VISITED)//if already visited
- return false;
- int temp=arr[i];//saving the value to set it back later
- arr[i]=VISITED;//making a flag of visited value;
- boolean result= isWay(arr, i-temp)||isWay(arr,i+temp);//going to left and right in distace of the value store in the current index
- arr[i]=temp;//setting back the original value
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement