본문 바로가기

IT/코딩테스트

[Leetcode] 791. Custom Sort String

728x90

https://leetcode.com/problems/custom-sort-string

class Solution:
    def customSortString(self, order: str, s: str) -> str:
        result = ''
        for i in order:
            for j in range(s.count(i)):
                result += i
                s = s.replace(i, '')
        result += s

        return result
728x90