mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0763.划分字符区间,添加C#
This commit is contained in:
@ -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">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user