Goal Parser Interpretation — LeetCode

Soren Rood
Dec 12, 2020

Here’s the question. It’s a LeetCode easy:

LeetCode Question #1678

There are a few ways you can solve this. You can do it in 23 lines with a loop, or you can use a simple Python function to solve in one line.

Here is my solution that is faster than 99.94% of 13,000 submissions:

https://carbon.now.sh

In the above solution, we iterate from 0 to the length of the command str. We append values to a string final as well as iterate depending on what the current character is. There is also a one-line python solution for this though.

return command.replace('()', o).replace('(al', al))

Here is the submission report for the 23 line solution above:

Pretty Quick

As always, my source code is located here and my social links are located here.

--

--