Skip to content

Instantly share code, notes, and snippets.

@uinz
Created July 25, 2018 09:46
Show Gist options
  • Save uinz/4580d4959f41716cc2b44ea37c1d10ee to your computer and use it in GitHub Desktop.
Save uinz/4580d4959f41716cc2b44ea37c1d10ee to your computer and use it in GitHub Desktop.
实现0和1的排列组合
function getArr(size: number) {
const result: number[][] = [];
(function loop(arr: number[] = []) {
if (arr.length < size) {
loop([...arr, 0]);
loop([...arr, 1]);
} else {
result.push(arr);
}
})();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment