You own a Goal Parser that can interpret a string
command consists of an alphabet of
"(al)" in some order. The Goal Parser will interpret
"G" as the string
"()" as the string
"(al)" as the string
"al". The interpreted strings are then concatenated in the original order.
Given the string
command, return the Goal Parser's interpretation of
Input: command = "G()(al)"
Explanation: The Goal Parser interprets the command as follows:
G -> G
() -> o
(al) -> al
The final concatenated result is "Goal".
Input: command = "G()()()()(al)"
1 <= command.length <= 100
"(al)"in some order.
1. Declare a output variable, to hold the value of each character match in the command variable2. Split command variable into an array, then iterate through each character in that array.3. If we see the character 'G', then add G to the output variable4. If we see the character '(', the code will then run the nested if statement5. If there is a ')' character at the following index, then we add 'o' to the output variable6. If there is are 'a', 'l', and ')' characters in the following 3, index of the command variable then we add 'al' to the output variable7. When we are done we return the output variable
# Runtime: 68 ms, faster than 72.00% of Ruby online submissions for Goal Parser Interpretation.# Memory Usage: 209.8 MB, less than 56.00% of Ruby online submissions for Goal Parser Interpretation.
Thanks for viewing. If you have any feedback on how to improve this code, leave a comment.