From 6add8c3287ade5bbfefd6d7042863376cff1ca39 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sat, 6 Jan 2024 09:33:13 +0800 Subject: [PATCH] =?UTF-8?q?Update=200435.=E6=97=A0=E9=87=8D=E5=8F=A0?= =?UTF-8?q?=E5=8C=BA=E9=97=B4=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/0435.无重叠区间.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md index c307532e..1a33f98e 100644 --- a/problems/0435.无重叠区间.md +++ b/problems/0435.无重叠区间.md @@ -441,6 +441,27 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int EraseOverlapIntervals(int[][] intervals) + { + if (intervals.Length == 0) return 0; + Array.Sort(intervals, (a, b) => a[1].CompareTo(b[1])); + int res = 1, end = intervals[0][1]; + for (int i = 1; i < intervals.Length; i++) + { + if (end <= intervals[i][0]) + { + end = intervals[i][1]; + res++; + } + } + return intervals.Length - res; + } +} +```