forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode1678.java
More file actions
27 lines (25 loc) · 772 Bytes
/
Leetcode1678.java
File metadata and controls
27 lines (25 loc) · 772 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
package com.company;
public class Leetcode1678 {
public static void main(String[] args) {
String str="G()()()()(al)";
String answer=interpret(str);
System.out.println(answer);
}
public static String interpret(String command) {
int i=0,l=command.length();
String updated="";
while (i<l){
if(command.substring(i,l).startsWith("G")){
updated=updated+"G";
i++;
} else if (command.substring(i,l).startsWith("()")){
updated=updated+"o";
i=i+2;
} else if (command.substring(i,l).startsWith("(al)")){
updated=updated+"al";
i=i+4;
}
}
return updated;
}
}