<jupyter_start><jupyter_text>Given a collection of numbers that might contain duplicates, return all possible unique permutations.**Example:**    Input: [1,1,2]    Output:    [      [1,1,2],      [1,2,1],      [2,1,1]    ]  ThoughtSimilar to 46. Permutations but additional hash table for memoization.<jupyter_code>def permuteUnique(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
    def helper(numlis,ans,res,cache):
        if str(ans) in cache: return
        if not numlis:
            res.append(ans[:])
            cache[str(ans)]=1
        for i in range(len(numlis)):
            if i!=0 and numlis[i]==numlis[i-1]:
                continue
            temp=numlis[:i]+numlis[i+1:]
            helper(temp,ans+[numlis[i]],res,cache) #numlis[:i]+numlis[i+1:] 一次跳過一個數字      
        return res

    return helper(nums,[],[],{})
def permuteUnique(self, nums):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """    
    res=[]
    def helper(nums,ans):
        if not nums:
            res.append(ans)
            return
        cache=set()
        for i,e in enumerate(nums):
            if e not in cache:
                cache.add(e)
                helper(nums[:i]+nums[i+1:],ans+[e])

    helper(nums,[])
    return res<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14823175319789314, 'fraction_numerical': 0.015048908954100828, 'mean_word_length': 2.1516587677725116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '642152', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 476, 'n_tokens_neox': 452, 'n_words': 97, 'path': '47. Permutations II.ipynb', 'repo_name': 'kkoo1122/Leetcode_Practice', 'size': '1329'}