mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
Update0376.摆动序列,添加C#
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user