알고리즘 공부
1306. Jump Game III
Sense.J
2020. 8. 20. 22:34
https://leetcode.com/problems/jump-game-iii/
Jump Game III - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
/**
* @param {number[]} arr
* @param {number} start
* @return {boolean}
*/
var canReach = function(arr, start) {
const hash = Array(arr.length).fill(false);
const find = function( p_idx )
{
if( p_idx < 0 || p_idx >= arr.length ) return false;
if( !arr[p_idx] ) return true;
if( !hash[p_idx] )
{
hash[p_idx] = true;
return find( p_idx + arr[p_idx] ) || find( p_idx - arr[p_idx] );
}
return false;
}
return find(start);
};