Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 429 Bytes

791.md

File metadata and controls

30 lines (21 loc) · 429 Bytes

Custom Sort String

Description

link


Solution

  • See Code

Code

O(n)

class Solution:
    def customSortString(self, S: str, T: str) -> str:
        cnt = Counter(T)
        res = ''
        for c in S:
            res += cnt[c] * c
            del(cnt[c])
        for c, t in cnt.items():
            res += t*c
        return res