# 1678. Goal Parser Interpretation ## 題目概要 將 `"G"` 轉為 `G`,將`()` 轉為 `o`,將`(al)` 轉為 `al`。 ``` Example 1: Input: command = "G()(al)" Output: "Goal" Explanation: The Goal Parser interprets the command as follows: G -> G () -> o (al) -> al The final concatenated result is "Goal". Example 2: Input: command = "G()()()()(al)" Output: "Gooooal" Example 3: Input: command = "(al)G(al)()()G" Output: "alGalooG" ``` ## 解題技巧 - 用 while 循環加 replace 解決。 ## 程式碼 ```javascript= /** * @param {string} command * @return {string} */ var interpret = function(command) { while (command.includes("(")) command = command.replace("()", "o").replace("(al)", "al") return command; }; ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up