(self, order: str, s: str)
| 1 | class Solution: |
| 2 | def customSortString(self, order: str, s: str) -> str: |
| 3 | char_count_of_s = {} |
| 4 | for i in s: |
| 5 | char_count_of_s[i] = char_count_of_s.get(i, 0) + 1 |
| 6 | |
| 7 | satisfied_string = "" |
| 8 | for char in order: |
| 9 | if char in char_count_of_s: |
| 10 | satisfied_string += char * char_count_of_s[char] |
| 11 | del char_count_of_s[char] |
| 12 | |
| 13 | for key,val in char_count_of_s.items(): |
| 14 | satisfied_string += key * val |
| 15 | |
| 16 | return satisfied_string |