forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path055-JumpGame.cs
More file actions
27 lines (24 loc) · 747 Bytes
/
055-JumpGame.cs
File metadata and controls
27 lines (24 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//-----------------------------------------------------------------------------
// Runtime: 96ms
// Memory Usage: 26.2 MB
// Link: https://leetcode.com/submissions/detail/330097809/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _055_JumpGame
{
public bool CanJump(int[] nums)
{
int maxRight = 0;
for (int i = 0; i < nums.Length; i++)
{
if (i > maxRight) { return false; }
if (i + nums[i] > maxRight)
maxRight = i + nums[i];
if (maxRight >= nums.Length - 1)
return true;
}
return false;
}
}
}