Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

solved 0046_Permutations problem on leetcode #806

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions LeetCode/0046_Permutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:

def rec(self, sinput, index, ans):
n = len(sinput)
if(index == n-1):
ans.append(sinput.copy())
return

for i in range(index, n):
sinput[i], sinput[index] = sinput[index], sinput[i]
self.rec(sinput, index+1, ans)
sinput[i], sinput[index] = sinput[index], sinput[i]

def permute(self, nums):
ans = []
index = 0
self.rec(nums, index, ans)
return ans