@@ -0,0 +1,2336 @@
+/**%0A * Problem Link: https://leetcode.com/problems/jump-game-ii/%0A * %0A * 1st, Using DFS, stack overflow.%0A * 2nd, Using BFS, timeout.%0A * 3rd, Using Greedy, Fancy.%0A */%0Aclass Node implements Comparable%3CNode%3E%7B%0A    public int index;%0A    public int step;%0A    %0A    public Node(int idx, int s) %7B%0A        index = idx;%0A        step = s;%0A    %7D%0A    %0A    public int compareTo(Node n) %7B%0A        return this.step - n.step;%0A    %7D%0A%7D%0Apublic class Solution %7B%0A    public int jump(int%5B%5D nums) %7B%0A        int ret = 0;%0A        int last = 0;%0A        int curr = 0;%0A        for (int i = 0; i %3C nums.length; ++i) %7B%0A            if (i %3E last) %7B%0A                last = curr;%0A                ++ret;%0A            %7D%0A            curr = Math.max(curr, i+nums%5Bi%5D);%0A        %7D%0A%0A        return ret;%0A    %7D%0A    public int jump_BFS(int%5B%5D nums) %7B%0A        int n = nums.length;%0A        boolean%5B%5D count = new boolean%5Bn%5D;%0A        %0A        PriorityQueue%3CNode%3E q = new PriorityQueue%3CNode%3E();%0A        q.add(new Node(0, 0));%0A        %0A        while(!q.isEmpty()) %7B%0A            Node x = q.poll();%0A            if(count%5Bx.index%5D) continue;%0A            count%5Bx.index%5D = true;%0A            int cost = x.step + 1;%0A            if(x.index == n - 1) return x.step;%0A            for(int c = nums%5Bx.index%5D; c%3E=1; c--) %7B%0A                int prev = x.index - c;%0A                int next = x.index + c;%0A                if(prev %3E= 0 && !count%5Bprev%5D) %7B%0A                    q.add(new Node(prev, cost));%0A                %7D%0A                if(next %3C nums.length && !count%5Bnext%5D) %7B%0A                    q.add(new Node(next, cost));%0A                %7D%0A            %7D%0A        %7D%0A        return -1;%0A    %7D%0A    %0A    private void jump(int%5B%5D nums, int%5B%5D count, int current) %7B%0A        if(current == nums.length - 1) return;%0A        for(int i=nums%5Bcurrent%5D; i%3E=1; i--) %7B%0A            int prev = current - i;%0A            int next = current + i;%0A            int cost = count%5Bcurrent%5D + 1;%0A            if(prev %3E= 0) %7B%0A                if(count%5Bprev%5D == -1 %7C%7C count%5Bprev%5D %3E cost) %7B%0A                    count%5Bprev%5D = cost;%0A                    jump(nums, count, prev);%0A                %7D%0A            %7D%0A            if(next %3C nums.length) %7B%0A                if(count%5Bnext%5D == -1 %7C%7C count%5Bnext%5D %3E cost) %7B%0A                    count%5Bnext%5D = cost;%0A                    jump(nums, count, next);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Create Jump_Game_II.java