mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #1210 from xiaofei-2020/greed07
添加(0055.跳跃游戏.md):增加typescript版本
This commit is contained in:
@ -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;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user