I don't know why failed on submit.

Problem: May leetcode challenge May 1st - May 7th: Jump Game II

Description: Test case pass well, but fail on submit in case of same test case....
i don't know reason..

class Solution {
    public static int min = 999999;
    
    public int jump(int[] nums) {
        doJump(nums, 0, 0);

        return min;
    }

    public void doJump(int[] nums, int idx, int jumpCount) {
        if (min <= jumpCount) {
            return;
        }

        // end of index
        if (idx == nums.length - 1) {
            min = jumpCount;
            return;
        }

        for (int i = nums[idx]; i >= 1; i--) {
            int nextIndex = idx + i;

            if (nextIndex >= nums.length) {
                i = nums.length - idx;
                continue;
            }

            doJump(nums, nextIndex, jumpCount + 1);
        }
    }
}

image

Comments (1)