题解 | #字符串的排列#

字符串的排列

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

由于字符串的内置函数较少,将字符串转化为列表,方便对其进行remove、append、insert等操作,输出结果时使用join方法将列表转化为字符串

class Solution:
    def Permutation(self , str: str) -> List[str]:
        # write code here
        result = []
        temp = []
        #num.sort()
        len_ = len(str)
        if not len_:
            return result
        if len_ == 1:
            result.append(str)
            return result
        str_list = list(str)
        def check(array):
            if len(temp) == len_:
                temp2 = ''.join(temp)
                if temp2 not in result:
                    result.append(temp2)
            else:
                for i in range(len(array)):
                    a = array[i]
                    temp.append(a)
                    array.remove(a)
                    check(array)
                    array.insert(i,a)
                    temp.pop()
        check(str_list)
        return result

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:23
转人工😡
门口唉提是地铁杀:五次握手了
点赞 评论 收藏
分享
Vincent777...:实习经历可以考虑放上去,对于软件使用方面可以细化一些,比如调整为:熟悉基于LSDYNA的瞬态动力学仿真分析,熟悉基于WORKBENCH的结构拓扑优化
我的简历长这样
点赞 评论 收藏
分享
zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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