Monday, September 8, 2014

Leetcode: Permutations @Python

class Solution:
    # @param num, a list of integer
    # @return a list of lists of integers
    def permute(self, num):
        n=len(num)
        rst=[[]]
        for i in range(n):
            rst=[r+[elem] for r in rst for elem in num if elem not in r]
        return rst      

No comments :

Post a Comment