Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ml): Update 55.jump-game.md #417

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions problems/55.jump-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Explanation: You will always arrive at index 3 no matter what. Its maximum

## 代码

- 语言支持: JavascriptPython3

- 语言支持: Javascript,C++,Java,Python3
Javascript Code:
```js
/**
* @param {number[]} nums
Expand All @@ -65,6 +65,55 @@ var canJump = function (nums) {
};
```

C++ Code:

```c++
class Solution {
public:
bool canJump(vector<int>& nums) {
int n=nums.size();
int k=0;
for(int i=0;i<n;i++)
{
if(i>k){
return false;
}
// 能跳到最后一个位置
if(k>=n-1){
return true;
}
// 从当前位置能跳的最远的位置
k = max(k, i+nums[i]);
}
return k >= n-1;
}
};
```

Java Code:

```java
class Solution {
public boolean canJump(int[] nums) {
int n=nums.length;
int k=0;
for(int i=0;i<n;i++)
{
if(i>k){
return false;
}
// 能跳到最后一个位置
if(k>=n-1){
return true;
}
// 从当前位置能跳的最远的位置
k = Math.max(k, i+nums[i]);
}
return k >= n-1;
}
}
```

Python3 Code:

```Python
Expand Down