mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加 0055.跳跃游戏.md C语言版本
This commit is contained in:
@ -154,6 +154,28 @@ var canJump = function(nums) {
|
||||
};
|
||||
```
|
||||
|
||||
### C
|
||||
```c
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
bool canJump(int* nums, int numsSize){
|
||||
int cover = 0;
|
||||
|
||||
int i;
|
||||
// 只可能获取cover范围中的步数,所以i<=cover
|
||||
for(i = 0; i <= cover; ++i) {
|
||||
// 更新cover为从i出发能到达的最大值/cover的值中较大值
|
||||
cover = max(i + nums[i], cover);
|
||||
|
||||
// 若更新后cover可以到达最后的元素,返回true
|
||||
if(cover >= numsSize - 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
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