REMOVE ADJACENT DUPLICATE IN STRING | PYTHON | LEETCODE # 1047

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • In this video we are solving Leetcode problem # 1047: Remove All Adjacent Duplicates in a String. This is a really straightforward stack based question that can be solved with a single iteration through the provided input.

Komentáře • 1

  • @mysteryman3472
    @mysteryman3472 Před 2 měsíci

    a simpler way to write te code would be
    class Solution:
    def removeDuplicates(self, s: str) -> str:
    stack = []
    for i in s:
    if stack and i == stack[-1]:
    stack.pop()
    else:
    stack.append(i)

    return ''.join(stack)
    nice explanation👍