Problem solving/Algorithms
[LeetCode] 1678. Goal Parser Interpretation (Python)
Young_A
2021. 1. 10. 09:55
LeetCode - Problems - Algorithms - 1678. Goal Parser Interpretation
Problem Description
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order.
The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al".
The interpreted strings are then concatenated in the original order.
Given the string command, return the Goal Parser's interpretations of command.
Example:
Constraints:
My Solution (Python)
class Solution(object):
def interpret(self, command):
"""
:type command: str
:rtype: str
"""
command = command.replace("()", "o")
command = command.replace("(al)", "al")
return command
์์ฃผ ๊ฐ๋จํ๊ฒ replace ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋๋ค.
G๋ ๊ทธ๋๋ก G๊ฐ ๋๋ฏ๋ก ์ ์ธํ๊ณ "()"->"o" ๊ทธ๋ฆฌ๊ณ "(al)" -> al ์ ์ํด ๋ ๋ฒ๋ง ์ฌ์ฉํ๋ฉด ๋๋ค.
return command.replace("()", "o").replace("(al)", "al")
์์ ๊ฐ์ด ํ ์ค๋ก๋ ์์ฑ๋ ์ ์๋ค.