| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/Monika-R/LeetCode-Solutions/master/Python/custom-sort-string.py | [Back] [Original] |
# Time: O(n)
# Space: O(1)
import collections
class Solution(object):
def customSortString(self, S, T):
"""
:type S: str
:type T: str
:rtype: str
"""
counter, s = collections.Counter(T), set(S)
result = [c*counter[c] for c in S]
result.extend([c*counter for c, counter in counter.iteritems() if c not in s])
return "".join(result)
| Web Proxy Viewer | New URL | Original Page |