Update0131.分割回文串

This commit is contained in:
eeee0717
2023-12-16 09:26:57 +08:00
parent 2cd982fd0d
commit 69a38ff1d3

View File

@ -847,6 +847,50 @@ object Solution {
}
}
```
### CSharp
```csharp
public class Solution
{
public IList<IList<string>> res = new List<IList<string>>();
public IList<string> path = new List<string>();
public IList<IList<string>> Partition(string s)
{
BackTracking(s, 0);
return res;
}
public void BackTracking(string s, int start)
{
if (start >= s.Length)
{
res.Add(new List<string>(path));
return;
}
for (int i = start; i < s.Length; i++)
{
if (IsPalindrome(s, start, i))
{
path.Add(s.Substring(start, i - start + 1));
}
else
{
continue;
}
BackTracking(s, i + 1);
path.RemoveAt(path.Count - 1);
}
}
public bool IsPalindrome(string s, int start, int end)
{
for (int i = start, j = end; i < j; i++, j--)
{
if (s[i] != s[j])
return false;
}
return true;
}
}
```
<p align="center">