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; +}; +``` + + + -----------------------