Leetcode - Remove Duplicate Letters (Python)

preview_player
Показать описание
October 2020 Leetcode Challenge
Leetcode - Remove Duplicate Letters # 316
Рекомендации по теме
Комментарии
Автор

Great explanation, was able to make sense of it easily.

stoup
Автор

it took me a while to figure out why answers for the example inputs were the way they were. nice video again Tim!

janmichaelaustria
Автор

shouldn't the condition be while (stack and stack[-1] > s[i] and lookup(stack[-1]) > i )
because its a subsequence and we are removing only duplicate letters?

treyi
Автор

Time Complexity of this solution is O(n). We would need to remove 26 elements from the stack at most at each iteration which sets O(1) as the cost of an iteration

oleksiimartens
Автор

Thank you very much for this video. Sir I have a query, why we are not using sorted function. As following
s='dcabde'
l=sorted(set(s))
print (l)

sharifmansuri
Автор

I like this solution! It seems like we don't actually need to use the seen set though? I removed it entirely and it still passes all test cases. We can just check if s[i] is in the stack.

HD-xnbr
Автор

how can i have just "a" in the output?i mean remove all two Consecutive letters
e.g:
input:hhoowaaaareyyoouu
expected output:wre

how can I do that?

sajiinsta
Автор

I feel silly for looking up the solution now, I shouldve been able to solve this. Need more determination

themagickalmagickman
Автор

Went the recursive way and regretted it :/

samarthasthana
visit shbcf.ru