Leetcode 55 跳跃游戏如何优化算法实现?

更新于
2026-09-24 00:33:50
24阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计166个文字,预计阅读时间需要1分钟。

Leetcode 55 跳跃游戏如何优化算法实现?

题目描述:给定一个整数数组,判断是否存在一条路径可以使得数组元素从大到小连续递减。

方法一:bool canJump(vector nums) { int k=0; for (int i=0; i k) return false; k=max(k, i + nums[i]); } return true;}

Leetcode 55 跳跃游戏如何优化算法实现?

题目描述

方法一

bool canJump(vector<int>& nums)
{
int k = 0;
for (int i = 0; i < nums.size(); i++)
{
if (i > k) return false;
k = max(k, i + nums[i]); #k为当前能向前跳的最大距离
}
return true;
}

参考链接
​​​ leetcode-cn.com/problems/jump-game/solution/55-by-ikaruga/​​

​​leetcode-cn.com/problems/jump-game/solution/tiao-yue-you-xi-by-leetcode/​​


本文共计166个文字,预计阅读时间需要1分钟。

Leetcode 55 跳跃游戏如何优化算法实现?

题目描述:给定一个整数数组,判断是否存在一条路径可以使得数组元素从大到小连续递减。

方法一:bool canJump(vector nums) { int k=0; for (int i=0; i k) return false; k=max(k, i + nums[i]); } return true;}

Leetcode 55 跳跃游戏如何优化算法实现?

题目描述

方法一

bool canJump(vector<int>& nums)
{
int k = 0;
for (int i = 0; i < nums.size(); i++)
{
if (i > k) return false;
k = max(k, i + nums[i]); #k为当前能向前跳的最大距离
}
return true;
}

参考链接
​​​ leetcode-cn.com/problems/jump-game/solution/55-by-ikaruga/​​

​​leetcode-cn.com/problems/jump-game/solution/tiao-yue-you-xi-by-leetcode/​​