Skip to content

Commit

Permalink
添加131.分割回文串JavaScript版本
Browse files Browse the repository at this point in the history
  • Loading branch information
flames519 committed Jun 5, 2021
1 parent ece55fe commit b6b04cc
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion problems/0131.分割回文串.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Solution {
```

Python:
```python3
```py
class Solution:
def partition(self, s: str) -> List[List[str]]:
res = []
Expand All @@ -313,7 +313,38 @@ class Solution:

Go:

javaScript:

```js
/**
* @param {string} s
* @return {string[][]}
*/
const isPalindrome = (s, l, r) => {
for (let i = l, j = r; i < j; i++, j--) {
if(s[i] !== s[j]) return false;
}
return true;
}

var partition = function(s) {
const res = [], path = [], len = s.length;
backtracking(0);
return res;
function backtracking(i) {
if(i >= len) {
res.push(Array.from(path));
return;
}
for(let j = i; j < len; j++) {
if(!isPalindrome(s, i, j)) continue;
path.push(s.substr(i, j - i + 1));
backtracking(j + 1);
path.pop();
}
}
};
```


-----------------------
Expand Down

0 comments on commit b6b04cc

Please sign in to comment.