Update0376.摆动序列,添加C#

This commit is contained in:
eeee0717
2023-12-26 09:12:03 +08:00
parent b01155fbf2
commit 7924803206

View File

@ -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">