mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update.0045跳跃游戏2,添加C#版本二
This commit is contained in:
@ -464,6 +464,27 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
```csharp
|
||||||
|
// 版本二
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public int Jump(int[] nums)
|
||||||
|
{
|
||||||
|
int cur = 0, next = 0, step = 0;
|
||||||
|
for (int i = 0; i < nums.Length - 1; i++)
|
||||||
|
{
|
||||||
|
next = Math.Max(next, i + nums[i]);
|
||||||
|
if (i == cur)
|
||||||
|
{
|
||||||
|
cur = next;
|
||||||
|
step++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return step;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user