# -*- coding:utf-8 -*-
class Solution:
    def Permutation(self, ss):
        # write code here
        res = []
        num = sorted(ss)
        if not num:
            return res
        while True:
            res.append(''.join(num))
            if not self.has_next_number(num):
                return res
        return res
    
    
    def has_next_number(self,num):
#         123541
        i = len(num)-1
        while i>0 and num[i]<=num[i-1]:
            i -= 1
        if i==0:
            return False
        j=i
        while j<len(num)-1 and num[j+1]>num[i-1]:
            j+=1
        num[i-1],num[j] = num[j],num[i-1]
        j = len(num)-1
        while i<j:
            num[i],num[j] = num[j],num[i]
            i+=1
            j-=1
        return True