diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md index ceea31fe..5c2241c8 100644 --- a/problems/0376.摆动序列.md +++ b/problems/0376.摆动序列.md @@ -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; + } +} +```