Just Similar to BFS search


  • 1
    J
    class Solution {
    public:
        int jump(vector<int>& nums) {
            if(nums.size() < 2) return 0;
            int level = 0;
            int start = 0;
            int end = start + 1;
            while(end < nums.size()){
                int nextEnd = end;
                for(int i = start; i < end; i++){
                    nextEnd = max(nextEnd, i + nums[i]);
                }
                level++;
                start = end;
                end = nextEnd + 1;
            }
            return level;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.