The TransCompilator

Solved LeetCode program · 874 of 1,000

#1190 · Reverse Substrings Between Each Pair of Parentheses

Medium String chunk-18.md

Original English source

Keep a shared stack as an empty list of text. Keep a shared current as empty text. Keep a shared word as empty text. Keep a shared flipped as empty text.

To turn. Set flipped to empty text. The last is the last position of word.
For every step from 0 to last.
The source is last minus step. The piece is the slice of word from source to source plus 1. Place piece into flipped.

To fold. The size is the last position of stack. The opened is item size of stack. remove the last item from stack. Set word to current. Turn. Place flipped into opened. Set current to opened.

The source is "(u(love)i)". The last is the last position of source.
For every spot from 0 to last.
The piece is the slice of source from spot to spot plus 1. If piece matches "(", Place current into stack, set current to empty text. If piece matches ")", fold. If piece does not match "(", If piece does not match ")", Place piece into current.

Show current.

Open in Playground Browse all 1,000 problems

Expected stdout

iloveu