编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
console.log("Hello world!            -  js.jsrun.net ");
function dfs(nums, visited, path, res) {
    if (path.length === nums.length) {
        res.add(path.join(''));
        return;
    }
    for (let i = 0; i < nums.length; i++) {
        if (visited[i]) continue;
        if (i > 0 && nums[i] === nums[i - 1] &&!visited[i - 1]) continue;
        visited[i] = true;
        path.push(nums[i]);
        dfs(nums, visited, path, res);
        path.pop();
        visited[i] = false;
    }
}

// let n = parseInt(input());
// let nums = input().split(' ');
// nums.sort();
let visited = new Array(3).fill(false);
let res = new Set();
dfs(["a", "b", "c"], [false, false, false], [], res);
console.log([...res].join('\n'));