【LeetCode热题100(74/100)】跳跃游戏

题目地址: 链接

思路: 每次记录能到达的最远距离,遍历结束后,如果能到达最后一位,return true,否则return false

ts 复制代码
function canJump(nums: number[]): boolean {
    const n = nums.length;
    let nowMaxJump = 0;
    for(let i = 0; i <= nowMaxJump && i < n; i ++) {
        nowMaxJump = Math.max(nowMaxJump, nums[i] + i);
    }
    return nowMaxJump >= n - 1 ? true : false
};
相关推荐
历程里程碑1 天前
普通数组----最大子数组和
大数据·算法·elasticsearch·搜索引擎·排序算法·哈希算法·散列表
52Hz1181 天前
力扣230.二叉搜索树中第k小的元素、199.二叉树的右视图、114.二叉树展开为链表
python·算法·leetcode
苦藤新鸡1 天前
56.组合总数
数据结构·算法·leetcode
菜鸟233号1 天前
力扣647 回文子串 java实现
java·数据结构·leetcode·动态规划
LiLiYuan.1 天前
【Cursor 中找不到LeetCode 插件解决办法】
算法·leetcode·职场和发展
Charlie_lll1 天前
力扣解题-[3379]转换数组
数据结构·后端·算法·leetcode
captain3761 天前
Java队列(Queue)
算法·链表
TracyCoder1231 天前
LeetCode Hot100(23/100)——142. 环形链表 II
算法·leetcode·链表
jigsaw_zyx1 天前
提示词工程
人工智能·算法