From 7924803206a0dc2b06b6d6f3c7281d9f56970a71 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Tue, 26 Dec 2023 09:12:03 +0800 Subject: [PATCH] =?UTF-8?q?Update0376.=E6=91=86=E5=8A=A8=E5=BA=8F=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0376.摆动序列.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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; + } +} +```