|
| 1 | +''' |
| 2 | + You own a Goal Parser that can interpret a string command. |
| 3 | + The command consists of an alphabet of "G", "()" and/or |
| 4 | + "(al)" in some order. The Goal Parser will interpret "G" |
| 5 | + as the string "G", "()" as the string "o", and "(al)" as |
| 6 | + the string "al". The interpreted strings are then |
| 7 | + concatenated in the original order. |
| 8 | +
|
| 9 | + Given the string command, return the Goal Parser's |
| 10 | + interpretation of command. |
| 11 | +
|
| 12 | + Example: |
| 13 | + Input: command = "G()(al)" |
| 14 | + Output: "Goal" |
| 15 | + Explanation: The Goal Parser interprets the command as |
| 16 | + follows: |
| 17 | + G -> G |
| 18 | + () -> o |
| 19 | + (al) -> al |
| 20 | + The final concatenated result is "Goal". |
| 21 | +
|
| 22 | + Example: |
| 23 | + Input: command = "G()()()()(al)" |
| 24 | + Output: "Gooooal" |
| 25 | +
|
| 26 | + Example: |
| 27 | + Input: command = "(al)G(al)()()G" |
| 28 | + Output: "alGalooG" |
| 29 | +
|
| 30 | + Constraints: |
| 31 | + - 1 <= command.length <= 100 |
| 32 | + - command consists of "G", "()", and/or "(al)" in some |
| 33 | + order. |
| 34 | +''' |
| 35 | +#Difficulty:Easy |
| 36 | +#105 / 105 test cases passed. |
| 37 | +#Runtime: 28 ms |
| 38 | +#Memory Usage: 14.2 MB |
| 39 | + |
| 40 | +#Runtime: 28 ms, faster than 90.84% of Python3 online submissions for Goal Parser Interpretation. |
| 41 | +#Memory Usage: 14.2 MB, less than 41.36% of Python3 online submissions for Goal Parser Interpretation. |
| 42 | + |
| 43 | +class Solution: |
| 44 | + def interpret(self, command: str) -> str: |
| 45 | + return command.replace('()', 'o').replace('(al)', 'al') |
0 commit comments