Solved LeetCode program · 903 of 1,000
#1249 · Minimum Remove to Make Valid Parentheses
Original English source
The text is "lee(t(c)o)de)". The keeps is a list of 13 zeros. The stack is an empty list of whole numbers.
For every spot from 0 to 12.
Set item spot of keeps to 1. The symbol is character spot of text. The depth is the number of items in stack. If symbol is "(", Place spot into stack. If symbol is ")" and depth is more than 0, remove the last item from stack. If symbol is ")" and depth is 0, set item spot of keeps to 0.
For every spot from 0 to the last position of stack.
Set item (item spot of stack) of keeps to 0.
The letters is an empty list of text.
For every spot from 0 to 12.
The piece is the slice of text from spot to spot plus 1. If item spot of keeps is 1, Place piece into letters.
The result is join letters with "". Show result.
Expected stdout
lee(t(c)o)de