1370. Increasing Decreasing String

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1370

class Solution:
    def sortString(self, s: str) -> str:
        cnt = Counter(s)
        cs = ascii_lowercase + ascii_lowercase[::-1]
        res = []
        while len(res) < len(s):
            for c in cs:
                if cnt[c]:
                    res.append(c)
                    cnt[c] -= 1
        return "".join(res)