File tree 2 files changed +12
-9
lines changed
solution/047.Permutations II
2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change
1
+ <p align =" center " >
2
+ <a href =" https://github.com/yanglbme/leetcode " ><img src =" http://p9ucdlghd.bkt.clouddn.com/leetcode-github.png " alt =" LeetCode-GitHub " ></a >
3
+ </p >
1
4
2
- ![ LeetCode-GitHub] ( http://p9ucdlghd.bkt.clouddn.com/leetcode-github.png )
5
+ <p align =" center " >
6
+ <a href =" http://makeapullrequest.com " ><img src =" https://img.shields.io/badge/PRs-Welcome-brightgreen.svg " alt =" PRs Welcome " ></a >
7
+ <a href =" https://github.com/yanglbme/leetcode " ><img src =" https://img.shields.io/badge/Lang-Java%2FPython%2FJS%2FCPP%2FGo%2F...-blue.svg " alt =" Language " ></a >
8
+ </p >
3
9
4
- <center >
5
-
6
- [ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-Welcome-brightgreen.svg )] ( http://makeapullrequest.com )
7
- [ ![ Language] ( https://img.shields.io/badge/Lang-Java%2FPython%2FJS%2FCPP%2FGo%2F...-blue.svg )] ( https://github.com/yanglbme/leetcode )
8
-
9
- </center >
10
+ <h2 align =" center " >LeetCode Solution</h2 >
10
11
11
12
## Introduction
12
13
Complete solutions to Leetcode problems, updated daily.
@@ -65,4 +66,4 @@ I'm looking for long-term contributors/partners to this repo! Send me PRs if you
65
66
| <center > [ <img src =" https://avatars3.githubusercontent.com/u/21008209?v=4 " width =" 100px; " /><br /><sub ><b >yanglbme</b ></sub >] ( https://github.com/yanglbme ) <br />[ 💻] ( https://github.com/yanglbme/leetcode/commits?author=yanglbme " Code ") </center > | <center > [ <img src =" https://avatars3.githubusercontent.com/u/23625436?v=4 " width =" 100px; " /><br /><sub ><b >chakyam</b ></sub >] ( https://github.com/chakyam ) <br />[ 💻] ( https://github.com/yanglbme/leetcode/commits?author=chakyam " Code ") </center > |
66
67
| ---| ---|
67
68
68
- <!-- ALL-CONTRIBUTORS-LIST:END -->
69
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
Original file line number Diff line number Diff line change 17
17
### 解法
18
18
将数组的首元素依次与数组的每个元素交换(两元素不相等才进行交换),对于每一轮交换,对后面的数组进行递归调用。当元素只剩下一个时,添加此时的数组到 list 中。
19
19
20
+ 注意:第 i 个数字与第 j 个数字交换时,要求[ i, j) 中没有与第 j 个数字相等的数。
21
+
20
22
``` java
21
23
class Solution {
22
24
public List<List<Integer > > permuteUnique (int [] nums ) {
@@ -51,7 +53,7 @@ class Solution {
51
53
private boolean isSwap (int [] nums , int from , int to ) {
52
54
for (int i = from; i < to; ++ i) {
53
55
if (nums[i] == nums[to]) {
54
- // 相等,不进行交换
56
+ // [from, to) 中出现与 第 to 个数相等的数,返回 false,不进行交换和全排列操作
55
57
return false ;
56
58
}
57
59
}
You can’t perform that action at this time.
0 commit comments