/** * * @param s string字符串 * @return string字符串二维数组 */ function partition( s ) { // write code here var result = []; var path = []; dfs(s,result,path); return result; } function dfs(s,result,path){ if(s.length<1){ result.push([...path]); return } for(var i=0;i<s.length;i++){ var begin = 0; var end = i; while(begin<end){ if(s[begin] == s[end]){ begin++ end-- }else break; } if(begin>=end){ path.push(s.substring(0,i+1)); dfs(s.substring(i+1),result,path); path.pop(); } } } module.exports = { partition : partition };