Solved LeetCode program · 785 of 1,000
#1021 · Remove Outermost Parentheses
Original English source
Keep a shared source as empty text. Place "(()())(())" into source. The built is empty text. The depth is 0.
For every spot from 0 to the last position of source.
The symbol is the slice of source from spot to spot plus 1. The opening is 0. If symbol is "(", set opening to 1. If opening is 1 and depth is more than 0, Place symbol into built. If opening is 1, add 1 to depth. If opening is 0, subtract 1 from depth. If opening is 0 and depth is more than 0, Place symbol into built.
Show built.
Expected stdout
()()()