• [LeetCode] Jump Game


    Given an array of non-negative integers, you are initially positioned at the first index of the array.

    Each element in the array represents your maximum jump length at that position.

    Determine if you are able to reach the last index.

    For example:
    A = [2,3,1,1,4], return true.

    A = [3,2,1,0,4], return false.

    Solution:

    class Solution {
    public:
        int *label;
        bool canJump(int A[], int n) {
            if(n == 0) return false;
            if(n == 1) return true;
            
            int curMax = A[0];
            for(int i = 0;i < n - 1;i++)
            {
                if(i > curMax) break;
                if(A[i] + i > curMax) curMax = A[i] + i;
                if(curMax >= n - 1) return true;
            }
            return false;
        }
    };
  • 相关阅读:
    day35
    Audio Unit 基础
    Audio Unit 介绍
    音频PCM编码
    iOS libyuv
    FFmpeg AVPacket
    FFmpeg AVCodec
    FFmpeg编译iOS静态库
    iOS-Cocoapods更新不及时
    iOS-读取txt文件中文乱码
  • 原文地址:https://www.cnblogs.com/changchengxiao/p/3592577.html
Copyright © 2020-2023  润新知