Skip to content

Commit cb7dd50

Browse files
committed
Update
Update
1 parent f3a3912 commit cb7dd50

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Python3/046_Permutations.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
'''
4+
Given a collection of distinct numbers, return all possible permutations.
5+
6+
For example,
7+
[1,2,3] have the following permutations:
8+
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
9+
'''
10+
11+
12+
class Solution(object):
13+
def permute(self, nums):
14+
"""
15+
:type nums: List[int]
16+
:rtype: List[List[int]]
17+
"""
18+
result = []
19+
self.get_permute([], nums, result)
20+
return result
21+
22+
def get_permute(self, current, num, result):
23+
if not num:
24+
result.append(current + [])
25+
return
26+
for i, v in enumerate(num):
27+
current.append(num[i])
28+
self.get_permute(current, num[:i] + num[i + 1:], result)
29+
current.pop()
30+
31+
32+
if __name__ == "__main__":
33+
assert Solution().permute([1, 2, 3]) == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
[![Language python](https://img.shields.io/badge/python-3.6-red.svg)](https://www.python.org)
44
[![License](https://img.shields.io/dub/l/vibe-d.svg)](https://opensource.org/licenses/MIT)
55

6-
This repository shares my experience in solving leetcode problems. I will update during half year. There are articles describing the solution. For further information, please see the [Articles](http://www.ranxiaolang.com/) part.
6+
This repository shares my experience in solving leetcode problems. I will update during half year. There are articles describing the solution. For further information, please see the [Resource](http://www.ranxiaolang.com/) part.
77

88
## Problems
99

1010
All the problems on [LeetCode](https://leetcode.com).
1111

12-
## Update
13-
14-
I have update [gavinfish's](https://github.com/gavinfish) code and make the code more correctly.
15-
1612
## License
1713

1814
[MIT LICENSE](./LICENSE)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy