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 8eefb2f

Browse files
add 面试题 08.08. 有重复字符串的排列组合
1 parent 7330473 commit 8eefb2f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

‎递归与回溯/LeetCode 212. 单词搜索 II.md

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L2doL2Nob2NvbGF0ZTE5OTkvY2RuL2ltZy8yMDIwMDgyODE0NTUyMS5qcGc?x-oss-process=image/format,png)
2+
>仰望星空的人,不应该被嘲笑
3+
4+
## 题目描述
5+
有重复字符串的排列组合。编写一种方法,计算某字符串的所有排列组合。
6+
7+
示例1:
8+
9+
```javascript
10+
输入:S = "qqe"
11+
输出:["eqq","qeq","qqe"]
12+
```
13+
14+
示例2:
15+
16+
```javascript
17+
输入:S = "ab"
18+
输出:["ab", "ba"]
19+
```
20+
21+
提示:
22+
23+
```javascript
24+
字符都是英文字母。
25+
字符串长度在[1, 9]之间。
26+
```
27+
28+
来源:力扣(LeetCode)
29+
链接:https://leetcode-cn.com/problems/permutation-ii-lcci
30+
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
31+
32+
## 解题思路
33+
34+
全排列,直接用回溯法即可,数据量比较小,暴力完事~
35+
36+
```javascript
37+
var permutation = function (S) {
38+
let res = new Set()
39+
let vis = []
40+
let dfs = (t) => {
41+
if (t.length === S.length) return res.add(t)
42+
for (let i = 0; i < S.length; i++) {
43+
if (vis[i]) continue
44+
vis[i] = true
45+
dfs(t + S[i])
46+
vis[i] = false
47+
}
48+
}
49+
dfs('')
50+
return [...res]
51+
}
52+
```
53+
54+
55+
## 最后
56+
文章产出不易,还望各位小伙伴们支持一波!
57+
58+
往期精选:
59+
60+
<a href="https://github.com/Chocolate1999/Front-end-learning-to-organize-notes">小狮子前端の笔记仓库</a>
61+
62+
<a href="https://yangchaoyi.vip/">访问超逸の博客</a>,方便小伙伴阅读玩耍~
63+
64+
![](https://img-blog.csdnimg.cn/2020090211491121.png#pic_center)
65+
66+
```javascript
67+
学如逆水行舟,不进则退
68+
```
69+
70+

0 commit comments

Comments
(0)

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