美文网首页
LeetCode_1370. Increasing Decrea

LeetCode_1370. Increasing Decrea

作者: 钱晓缺 | 来源:发表于2020-07-09 17:01 被阅读0次

要点:1.set函数,生产不重复的数据集

2. sorted(),不改变原数据的排序

3.replace, 第一个参数,被替换的值,第二,替换的值,第三,替换的个数

class Solution(object):

    def sortString(self, s):

        """

        :type s: str

        :rtype: str

        s=rt

        new = a r t

        i

        res=ar

        """

        new=sorted(set(s))

        res=""

        while s:

            for i in new:

                if i in s:

                    res+=i

                    s=s.replace(i,'',1)

            for i in new[::-1]:

                if i in s:

                    res+=i

                    s=s.replace(i,'',1)

        return res

相关文章

网友评论

      本文标题:LeetCode_1370. Increasing Decrea

      本文链接:https://www.haomeiwen.com/subject/eluscktx.html