diff --git "a/problems/0077.\347\273\204\345\220\210.md" "b/problems/0077.\347\273\204\345\220\210.md" index e582daf6bc..4560c5b7eb 100644 --- "a/problems/0077.\347\273\204\345\220\210.md" +++ "b/problems/0077.\347\273\204\345\220\210.md" @@ -456,6 +456,27 @@ const combineHelper = (n, k, startIndex) => { } ``` +## TypeScript + +```typescript +function combine(n: number, k: number): number[][] { + let resArr: number[][] = []; + function backTracking(n: number, k: number, startIndex: number, tempArr: number[]): void { + if (tempArr.length === k) { + resArr.push(tempArr.slice()); + return; + } + for (let i = startIndex; i <= n - k + 1 + tempArr.length; i++) { + tempArr.push(i); + backTracking(n, k, i + 1, tempArr); + tempArr.pop(); + } + } + backTracking(n, k, 1, []); + return resArr; +}; +``` + ## Go