Skip to content

Commit

Permalink
46 permutation
Browse files Browse the repository at this point in the history
  • Loading branch information
RochaC authored and chenzh committed Mar 7, 2020
1 parent dd384bc commit 2dc82a2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 46_Permutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
" File Description:
"
"
" Created by Rocha(chenzhihao) on 2020/3/5.
"""



class Solution(object):
def __init__(self):
self.res = []

def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
self._permute([], nums)

return self.res

def _permute(self, stack, nums):
if len(stack) == len(nums):
self.res.append(stack[:])
else:
for i in nums:
if i not in stack:
stack.append(i)
self._permute(stack, nums)
stack.pop()
else:
continue

return


if __name__ == '__main__':
so = Solution()
so.permute([1,2,3])
print(so.res)

0 comments on commit 2dc82a2

Please sign in to comment.