From 6e09456aefe7981d272e355c28e4ab43597ac5b1 Mon Sep 17 00:00:00 2001 From: Steve2020 <841532108@qq.com> Date: Wed, 6 Apr 2022 23:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=880055.=E8=B7=B3?= =?UTF-8?q?=E8=B7=83=E6=B8=B8=E6=88=8F.md=EF=BC=89=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0typescript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0055.跳跃游戏.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md index c0890f75..94614242 100644 --- a/problems/0055.跳跃游戏.md +++ b/problems/0055.跳跃游戏.md @@ -154,6 +154,23 @@ var canJump = function(nums) { }; ``` +### TypeScript + +```typescript +function canJump(nums: number[]): boolean { + let farthestIndex: number = 0; + let cur: number = 0; + while (cur <= farthestIndex) { + farthestIndex = Math.max(farthestIndex, cur + nums[cur]); + if (farthestIndex >= nums.length - 1) return true; + cur++; + } + return false; +}; +``` + + + -----------------------