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 39ce780

Browse files
add LeetCode 77. 组合
1 parent e5ef292 commit 39ce780

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L2doL2Nob2NvbGF0ZTE5OTkvY2RuL2ltZy8yMDIwMDgyODE0NTUyMS5qcGc?x-oss-process=image/format,png)
2+
>仰望星空的人,不应该被嘲笑
3+
4+
## 题目描述
5+
6+
给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。
7+
8+
示例:
9+
10+
```javascript
11+
输入: n = 4, k = 2
12+
输出:
13+
[
14+
[2,4],
15+
[3,4],
16+
[2,3],
17+
[1,2],
18+
[1,3],
19+
[1,4],
20+
]
21+
```
22+
23+
来源:力扣(LeetCode)
24+
链接:https://leetcode-cn.com/problems/combinations
25+
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
26+
27+
28+
29+
## 解题思路
30+
直接套用组合题解题模板即可
31+
32+
```javascript
33+
var combine = function (n, k) {
34+
let res = [];
35+
let dfs = (t, start) => {
36+
if (t.length === k) {
37+
res.push(t);
38+
return;
39+
}
40+
for (let i = start; i <= n; i++) {
41+
t.push(i);
42+
dfs(t.slice(), i + 1);
43+
t.pop();
44+
}
45+
}
46+
dfs([], 1);
47+
return res;
48+
};
49+
```
50+
51+
52+
## 最后
53+
文章产出不易,还望各位小伙伴们支持一波!
54+
55+
往期精选:
56+
57+
<a href="https://github.com/Chocolate1999/Front-end-learning-to-organize-notes">小狮子前端の笔记仓库</a>
58+
59+
<a href="https://yangchaoyi.vip/">访问超逸の博客</a>,方便小伙伴阅读玩耍~
60+
61+
![](https://img-blog.csdnimg.cn/2020090211491121.png#pic_center)
62+
63+
```javascript
64+
学如逆水行舟,不进则退
65+
```
66+
67+
68+

0 commit comments

Comments
(0)

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