题解 | #字符串的排列#

字符串的排列

http://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7

# -*- coding:utf-8 -*-
class Solution:
    def __init__(self):
        self.a = []
        self.ret = []
        
        
    def permuRecur(self, chars, idx, n):
        if idx == n:
            self.ret.append(''.join(self.a))
#             self.a = []
            return
#         print("idx:", idx)
        for idxTmp, ch in enumerate(chars[::]):
            
            self.a.append(ch)
#             print(self.a)
            chars.pop(idxTmp)
            self.permuRecur(chars, idx+1, n)
            chars.insert(idxTmp, ch)
            self.a.pop()
            
    def Permutation(self, ss):
        # write code here
        chars =[]
        for item in ss:
            chars.append(item)
#         print("chars:", chars)
        self.permuRecur(chars,0, len(chars))
        return list(set(self.ret))
        
        
        
全部评论

相关推荐

合不合适,我自己说了才算
码农索隆:hr:“真执着啊,来我公司当法人吧”
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务