u/satyamvanshalmusic

Suggestions to further improve my code for today's LeetCode Challenge

Submitted today's LeetCode Challenge i.e. 678. Valid Parenthesis String and it got accepted. However, I felt the need to ask the internet to judge my code and help me improve it further. I used two stacks for this one :)

Here's the code:

q = []
star_q = []
i = 0

for char in s:
    if char == ')':
        if q:
            q.pop()
        elif star_q:
            star_q.pop()
        else:
            return False
    else:
        if char == '*':
            star_q.append((char, i))
        else:
            q.append((char, i))

    i += 1

while star_q and q:
    if star_q[-1][1] > q[-1][1]:
        q.pop()

    star_q.pop()

return not q
reddit.com
u/satyamvanshalmusic — 11 days ago