-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy全排列.py
More file actions
35 lines (27 loc) · 741 Bytes
/
Copy pathpy全排列.py
File metadata and controls
35 lines (27 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# !/usr/bin/python
# -*- coding: utf-8 -*-
"""
@File : py全排列.py
@Time : 2020/12/31 14:24:06
@Author : mayuan
@Version : 1.0
@Contact : 2901429479@qq.com
@License : (C)Copyright 2020-2021
@Desc : None
"""
class Solution(object):
def permutations(self,nums):
res = []
def helper(start):
if start==len(nums):
res.append(nums[:])
for i in range(start, len(nums)):
nums[i],nums[start] = nums[start], nums[i]
helper(start+1)
nums[i],nums[start] = nums[start], nums[i]
helper(0)
return res
if __name__ == "__main__":
s =Solution()
nums = [1,2,3]
print(s.permutations(nums))