-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode1678_GoalParser.java
More file actions
33 lines (29 loc) · 1019 Bytes
/
Copy pathleetcode1678_GoalParser.java
File metadata and controls
33 lines (29 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class leetcode1678_GoalParser {
public String interpret(String command) {
String temp = command;
StringBuilder sb = new StringBuilder();
while(temp.length()!= 0){
if(temp.startsWith("G")) {
sb.append("G");
temp = temp.replaceFirst("G","");
}
else if(temp.startsWith("()")) {
sb.append("o");
temp = temp.replaceFirst("(\\(\\))","");
}
else if(temp.startsWith("(al)")) {
sb.append("al");
temp = temp.replaceFirst("(\\()","");
temp = temp.replaceFirst("al","");
temp = temp.replaceFirst("(\\))","");
}
}
return sb.toString();
}
public static void main(String[] args) {
String str = "(al)G(al)()()G";
leetcode1678_GoalParser obj = new leetcode1678_GoalParser();
String res = obj.interpret(str);
System.out.println(res);
}
}