From 20f331f9043725ad9c39d27bf9912c441b6bcf48 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sun, 7 Jan 2024 10:04:45 +0800 Subject: [PATCH] =?UTF-8?q?Update=200763.=E5=88=92=E5=88=86=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=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/0763.划分字母区间.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md index 41314456..4e9ec578 100644 --- a/problems/0763.划分字母区间.md +++ b/problems/0763.划分字母区间.md @@ -404,6 +404,32 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public IList PartitionLabels(string s) + { + int[] location = new int[27]; + for (int i = 0; i < s.Length; i++) + { + location[s[i] - 'a'] = i; + } + List res = new List(); + int left = 0, right = 0; + for (int i = 0; i < s.Length; i++) + { + right = Math.Max(right, location[s[i] - 'a']); + if (i == right) + { + res.Add(right - left + 1); + left = i + 1; + } + } + return res; + } +} +```