Movatterモバイル変換


[0]ホーム

URL:


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

Commitcb7dd50

Browse files
committed
Update
Update
1 parentf3a3912 commitcb7dd50

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+
classSolution(object):
13+
defpermute(self,nums):
14+
"""
15+
:type nums: List[int]
16+
:rtype: List[List[int]]
17+
"""
18+
result= []
19+
self.get_permute([],nums,result)
20+
returnresult
21+
22+
defget_permute(self,current,num,result):
23+
ifnotnum:
24+
result.append(current+ [])
25+
return
26+
fori,vinenumerate(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+
assertSolution().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)

[8]ページ先頭

©2009-2025 Movatter.jp