CUSTOM SORT STRING | PYTHON | LEETCODE # 791

preview_player
Показать описание
In this video we are solving Leetcode problem # 761: Custom Sort String. It's a relatively simple question using a string builder and a counts dictionary.
Рекомендации по теме
Комментарии
Автор

The explanation are just as good as NeetCode

yixinzhao
Автор

Had to comment. The explanation was so clear. Keep up the good work man!

susanpoudel
Автор

Great explanation, thanks for sharing

ahmedtremo
Автор

Love your solution here is another one if you want to build the string straight up leave comments on what you think
class Solution:
def customSortString(self, order: str, s: str) -> str:
h_map = collections.Counter(s)

ans = ""
for i in order:
if i in h_map:
ans += i * h_map[i]
h_map.pop(i)

for i in h_map:
ans += i * h_map[i]

return ans

richardekwenibe
Автор

love your solution, i can understand totally . thanks

xiaoxiaoliu
Автор

constant space because there's only 26 unique chars in s right?

krishivgubba
visit shbcf.ru