mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +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">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
|
Reference in New Issue
Block a user