Created
March 15, 2019 03:17
-
-
Save ChongyeWang/1bdd9b08cd2c8bb0e0668f96b5cbcc26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def permuteUnique(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[List[int]] | |
""" | |
nums = sorted(nums) | |
temp = [] | |
result = [] | |
used = [0 for _ in range(len(nums))] | |
self.backtracking(temp, result, nums, used) | |
return result | |
def backtracking(self, temp, result, nums, used): | |
if(len(temp) == len(nums)): | |
result.append(temp[:]) | |
for i in range(0, len(nums)): | |
if used[i] == 1: continue | |
if i > 0 and nums[i] == nums[i - 1] and used[i - 1] == 0: continue | |
used[i] = 1 | |
temp.append(nums[i]) | |
self.backtracking(temp, result, nums, used) | |
temp.pop() | |
used[i] = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment