MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / customSortString

Method customSortString

python/0791-custom-sort-string.py:2–16  ·  view source on GitHub ↗
(self, order: str, s: str)

Source from the content-addressed store, hash-verified

1class 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

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected