题解 | #全排列#

全排列

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;
};

全部评论

相关推荐

04-06 16:59
已编辑
河南工业大学 Java
牛牛牛的牛子:最好扔了,实在没有选择的选择
点赞 评论 收藏
分享
04-08 13:31
已编辑
门头沟学院 前端工程师
D0cC:京东营收1万多亿人民币,阿里9000多亿,虽然他俩利润都没腾讯和字节多,但是很恐怖了啊,负担了多少打工人的薪水
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务