The TransCompilator

Solved LeetCode program · 20 of 1,000

#0020 · Valid Parentheses

Easy String chunk-01.md

Original English source

The word is "()[]{}". The last is the last position of word. The stack is an empty list of whole numbers. The invalid is 0. The top is 0.
For every position from 0 to last.
The symbol is character position of word. The size is the number of items in stack. If symbol is "(" or symbol is "[" or symbol is "{", Place symbol into stack. If symbol is ")" and size is 0, add 1 to invalid. If symbol is ")" and size is more than 0, set top to item (size minus 1) of stack, remove the last item from stack, if top is not "(", add 1 to invalid. If symbol is "]" and size is 0, add 1 to invalid. If symbol is "]" and size is more than 0, set top to item (size minus 1) of stack, remove the last item from stack, if top is not "[", add 1 to invalid. If symbol is "}" and size is 0, add 1 to invalid. If symbol is "}" and size is more than 0, set top to item (size minus 1) of stack, remove the last item from stack, if top is not "{", add 1 to invalid.

The finalsize is the number of items in stack. If invalid is 0 and finalsize is 0, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true