0%

Leetcode 1678. Goal Parser Interpretation

題目

1
2
3
4
5
6
7
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".

解法思維

利用replace()正規表達式

1
var interpret =(command)=>command.replace(/\(\)/g,'o').replace(/\((\w)(\w)\)/g,"$1$2");