Update 0763.划分字符区间,添加C#

This commit is contained in:
eeee0717
2024-01-07 10:04:45 +08:00
parent 6add8c3287
commit 20f331f904

View File

@ -404,6 +404,32 @@ impl Solution {
}
}
```
### C#
```csharp
public class Solution
{
public IList<int> PartitionLabels(string s)
{
int[] location = new int[27];
for (int i = 0; i < s.Length; i++)
{
location[s[i] - 'a'] = i;
}
List<int> res = new List<int>();
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;
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">