filmov
tv
Remove all adjacent duplicates problem optimization and stack review | Leet Code Python

Показать описание
In this video we improve on the original implementation by converting our recursive algorithm into an iterative one that uses a return string as a stack. We can do this by using the built in python string concatenation, splitting, and negative indexing to reproduce the equivalent push, pop, and peek functions of a stack. Using this data structure we can significantly improve the readability of our code compared to the recursive algorithm.
This is from LeetCode problem 1047 "Remove All Adjacent Duplicates In String"
Original implementation:
Data structure summary:
Python List Breakdown and Usage:
This is from LeetCode problem 1047 "Remove All Adjacent Duplicates In String"
Original implementation:
Data structure summary:
Python List Breakdown and Usage: