添加(0131.分割回文串.md):增加typescript版本

This commit is contained in:
Steve2020
2022-03-30 16:40:18 +08:00
parent 1d19c5ba79
commit f0b771af5c

View File

@ -450,6 +450,38 @@ var partition = function(s) {
}; };
``` ```
## TypeScript
```typescript
function partition(s: string): string[][] {
function isPalindromeStr(s: string, left: number, right: number): boolean {
while (left < right) {
if (s[left++] !== s[right--]) {
return false;
}
}
return true;
}
function backTracking(s: string, startIndex: number, route: string[]): void {
let length: number = s.length;
if (length === startIndex) {
resArr.push(route.slice());
return;
}
for (let i = startIndex; i < length; i++) {
if (isPalindromeStr(s, startIndex, i)) {
route.push(s.slice(startIndex, i + 1));
backTracking(s, i + 1, route);
route.pop();
}
}
}
const resArr: string[][] = [];
backTracking(s, 0, []);
return resArr;
};
```
## C ## C
```c ```c