/**
* @param {string} s
* @return {string[][]}
*/
var partition = function(s) {
let res = []
let path = []
const backTracking = function(s, startIndex){
if(startIndex === s.length){
res.push([...path])
return
}
for(let i = startIndex; i < s.length; i++){
if(isP(s, startIndex, i)){
path.push(s.substring(startIndex, i+1))
}else{ continue }
backTracking(s, i+1)
path.pop()
}
}
backTracking(s, 0)
return res
};
function isP(s, start, end){
for (let i = start, j = end; i < j; i++, j--) {
if (s[i] !== s[j]) {
return false;
}
}
return true;
}
131. 分割回文串
最新推荐文章于 2024-07-10 15:12:36 发布