문제풀이 2021 01 18
2021.01.18 연습
- 사용언어 : java
class Solution {
public String interpret(String command) {
command = command.replaceAll("\\(\\)", "o").replaceAll("\\(al\\)", "al");
return command;
}
}
Runtime: 4 ms, faster than 14.78% of Java online submissions for Goal Parser Interpretation. Memory Usage: 38.2 MB, less than 31.85% of Java online submissions for Goal Parser Interpretation.
- 다른 코드 참고
public String interpret(String command) {
char[] arr = command.toCharArray();
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < arr.length ; ){
if(arr[i]=='G'){
sb.append("G");
i++;
}
else if(arr[i]=='(' && arr[i+1]!=')'){
sb.append("al");
i += 4;
}
else{
sb.append("o");
i+=2;
}
}
return sb.toString();
}