题解 | #字符串的排列#
字符串的排列
http://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7
function Permutation(s)
{
// write code here
if (s.length === 0) return [];
if (s.length === 1) return [s];
const res = [];
let len = s.length;
for (let i = 0; i < len; i++) {
const char = s.charAt(i);
const newStr = s.slice(0, i) + s.slice(i + 1);
const next = Permutation(newStr);
next.forEach((str) => {
res.push(char + str);
})
}
return [...new Set(res)];
}
module.exports = {
Permutation : Permutation
};