Update.0045跳跃游戏2,添加C#版本二
This commit is contained in:
parent
e209d35143
commit
a66e5e39ba
|
|
@ -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">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue