116. Jump Game

class Solution { public: /** * @param A: A list of integers * @return: A boolean */ bool canJump(vector<int> &A) { // write your code here const int size = A.size(); if(size == 0){ return false; } int longest = 0 + A[0]; for(int i = 1; i < size; i++){ if(longest >= i){ longest = max(longest, i + A[i]); } } return longest >= size - 1; } };

Comments

Popular posts from this blog

1427. Split Array into Fibonacci Sequence

Amazon OA 763. Partition Labels

05/25 周一