Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 513b98f

Browse files
update: 77
1 parent 4cb4383 commit 513b98f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
5959
| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path/) | [JavaScript](./src/simplify-path/res.js) | Medium |
6060
| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [JavaScript](./src/set-matrix-zeroes/res.js) | Medium |
6161
| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors/) | [JavaScript](./src/sort-colors/res.js) | Medium |
62+
| 77 | [combinations](https://leetcode.com/problems/combinations/) | [TypeScript](./src/combinations/res.ts) | Medium |
6263
| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) | [JavaScript](./src/remove-duplicates-from-sorted-array-ii/res.js) | Medium |
6364
| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/) | [JavaScript](./src/search-in-rotated-sorted-array-ii/res.js) | Medium |
6465
| 88 | [ Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | [JavaScript](./src/merge-sorted-array/res.js) | Medium |

‎src/combinations/res.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function iterateNums(nums: number[], k: number): number[][] {
2+
if (k === 0) {
3+
return [];
4+
}
5+
6+
const result: number[][] = [];
7+
nums.forEach((num, index) => {
8+
const newNums = nums.slice(index+1);
9+
const newResult = iterateNums([...newNums], k - 1);
10+
11+
if (newResult.length) {
12+
newResult.forEach(item => {
13+
result.push([num, ...item]);
14+
});
15+
} else {
16+
result.push([num]);
17+
}
18+
});
19+
20+
return result.filter(item => item.length === k);
21+
}
22+
23+
function combine(n: number, k: number): number[][] {
24+
const nums = (new Array(n).fill(0)).map((_, index) => index + 1);
25+
return iterateNums(nums, k);
26+
};

‎src/permutations-ii/res.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function getUniqueList(numsCountMap: { [key in number]: number }): number[][] {
1010

1111
if (currentCount) {
1212
const newNumsCountMap = { ...numsCountMap };
13+
// @ts-ignore
1314
newNumsCountMap[key]--;
1415
for (let newKey in newNumsCountMap) {
1516
if (!newNumsCountMap[newKey]) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /