标签:int for tor leetcode max i++ size col cto
//很巧妙的贪心算法 reach = max(reach,nums[i] + i);
class Solution { public: bool canJump(vector<int>& nums) { int n = nums.size(); int reach = 0; for(int i=0;i < n;i++){ if(i > reach || reach >= n-1) break; reach = max(reach,nums[i] + i); } return reach >= n-1; } };
标签:int for tor leetcode max i++ size col cto
原文地址:https://www.cnblogs.com/cunyusup/p/9755326.html