<문제 1678. Goal Parser Interpretation>
[문제]
번역 :
[문자열 명령을 해석할 수 있는 Goal Parser를 가지고 있습니다. 명령은 "G", "()" 및/또는 "(al)"의 알파벳 순서로 구성되어 있습니다. Goal Parser는 "G"를 문자열 "G"로, "()"를 문자열 "o"로, "(al)"를 문자열 "al"로 해석합니다. 그런 다음 해석된 문자열은 원래 순서대로 연결됩니다.
문자열 명령이 주어지면 Goal Parser의 해석을 반환합니다.]
→ Goal Parser라는 장치를 이용해 "()"를 "o"로, "(al)"을 "al"로 변환시켜주면 되는 문제
나는 replace를 사용해서 풀이했다.
[답안]
class Solution {
public String interpret(String command) {
return command.replace("()", "o").replace("(al)","al");
}
public static void main(String[] args){
Solution sol = new Solution();
String command = "G()(al)";
String command2 = "G()()()()(al)";
String command3 = "(al)G(al)()()G";
System.out.println(sol.interpret(command));
System.out.println(sol.interpret(command2));
System.out.println(sol.interpret(command3));
}
}
출처
https://rimmee97.tistory.com/217
[leetcode] 1365. How Many Numbers Are Smaller Than the Current Number (java)
[문제] 번역 : [배열 nums가 주어졌을 때, 각 nums[i]에 대해 배열에서 이보다 작은 숫자가 몇 개 있는지 구합니다. 즉, 각 nums[i]에 대해 j != i, nums[j] nums[j]) cnt++; // 만약 j값이 i보다 작으면 카운트++ } a
rimmee97.tistory.com
'알고리즘 풀이(JAVA) > leetcode' 카테고리의 다른 글
[leetcode] 1528. Shuffle String (java) (0) | 2023.04.11 |
---|---|
[leetcode] 1281. Subtract the Product and Sum of Digits of an Integer (java) (0) | 2023.03.30 |
[leetcode] 1365. How Many Numbers Are Smaller Than the Current Number (java) (2) | 2023.03.14 |
[leetcode] 1431. Kids With the Greatest Number of Candies (java) (2) | 2023.03.11 |
[leetcode] 2574. Left and Right Sum Differences (java) (0) | 2023.02.27 |