题解 | #全排列#

全排列

https://www.nowcoder.com/practice/b3ac35e1569e4601b6d3957dd337e70b

const _permute = (string) => {
	let flag = new Array(string.length).fill(0);
	const len = string.length;
	let result = [];
	let res = "";
	function d() {
		if (res.length === len) {
			result.push(res);
			res = "";
			// res.slice(-1);
			// flag = new Array(string.length).fill(0);
			return;
		}
		for (let i = 0; i < len; ++i) {
			if (!flag[i]) {
				let temp = res;
				flag[i] = 1;
				res = res + string[i];
				d();
				flag[i] = 0;
				res = temp;
			}
		}
	}
	d();
	console.log(result);
	return result;
};

全部评论

相关推荐

喜欢疯狂星期四的猫头鹰在研究求职打法:短作业优先
点赞 评论 收藏
分享
抱抱碍事梨a:三点建议,第一点是建议再做一个项目,把自我介绍部分顶了,第二点是中南大学加黑加粗,第三点是建议加v详细交流
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务