Update0376.摆动序列,添加C#
This commit is contained in:
parent
b01155fbf2
commit
7924803206
|
|
@ -692,6 +692,27 @@ object Solution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
```csharp
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public int WiggleMaxLength(int[] nums)
|
||||||
|
{
|
||||||
|
if (nums.Length < 2) return nums.Length;
|
||||||
|
int curDiff = 0, preDiff = 0, res = 1;
|
||||||
|
for (int i = 0; i < nums.Length - 1; i++)
|
||||||
|
{
|
||||||
|
curDiff = nums[i + 1] - nums[i];
|
||||||
|
if ((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0))
|
||||||
|
{
|
||||||
|
res++;
|
||||||
|
preDiff = curDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<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