leetcode第一刷_Jump Game
LeetCode 第一 Game Jump
2023-09-14 09:10:27 时间
这个题事实上非常easy的,我一開始想复杂了,它没要求记录路径,事实上仅仅要看一下每一步之后所能延伸到的最远的位置就能够了,在这一个最远位置前面的那些位置,都是能够到达的,假设扫到了某个i,它大于当前能延伸到到的最远位置,说明这个i不可达。终于的位置能不能到达,就看终于延伸到的位置能不能大于等于它。
class Solution { public: bool canJump(int A[], int n) { if(n == 0) return false; if(n == 1) return true; int mmax = 0; for(int i=0;i<n-1&&i<=mmax;i++){ if(i+A[i]>mmax) mmax = i+A[i]; if(mmax>=n-1) return true; } return false; } };
相关文章
- Java实现 LeetCode 472 连接词
- Java实现 LeetCode 416 分割等和子集
- Java实现 LeetCode 241 为运算表达式设计优先级
- Java实现 LeetCode 142 环形链表 II(二)
- Java实现 LeetCode 67 二进制求和
- leetcode第一刷_Word Search
- 【LeetCode】Partition List
- leetcode - Merge Intervals
- leetcode-1 Two Sum 找到数组中两数字和为指定和
- leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal