LeetCode – 45. Jump Game II

題目連結: https://leetcode.com/problems/jump-game-ii/

參考解法: https://www.youtube.com/watch?v=dJ7sWiOoK7g

    func jump(_ nums: [Int]) -> Int {
        var step = 0
        var left = 0
        var right = 0
        while right < (nums.count - 1) {
            var farthest = 0
            for i in left ..< (right + 1) {
                farthest = max(farthest, i + nums[i])
            }
            left = right + 1
            right = farthest
            step += 1
        }
        return step
    }