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")
์์ ๊ฐ์ด ํ ์ค๋ก๋ ์์ฑ๋ ์ ์๋ค.
'Problem solving > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Daily Challenge Merge Sorted Array (Python) (0) | 2021.01.12 |
---|---|
[LeetCode] 1684. Count the Number of Consistent Strings (Python) (0) | 2021.01.10 |
[LeetCode] 1603. Design Parking System (Python) (0) | 2021.01.10 |
[LeetCode] 1528. Shuffle String (Python) (0) | 2021.01.10 |
[LeetCode] 1512. Number of Good Pairs (Python) (0) | 2021.01.10 |