
class Solution {
public int solution(String s) {
String[] sArray = s.split(" ");
int result = 0;
for (int i = 0; i < sArray.length; i++) {
if (sArray[i].equals("Z")) {
result -= Integer.parseInt(sArray[i - 1]);
continue;
}
result += Integer.parseInt(sArray[i]);
}
return result;
}
}
public int solution (String s) {
int answer = 0;
Stack<Integer> stack = new Stack<>();
for (String w : s.split(" ")) {
if (w.equals("Z")) {
stack.pop();
} else {
stack.push(Integer.parseInt(w));
}
}
for (int i : stack) {
answer += i;
}
return answer;
}

class Solution {
public int[] solution(String[] strlist) {
int[] answer = new int[strlist.length];
for (int i = 0; i < answer.length; i++) {
answer[i] = strlist[i].length();
}
return answer;
}
}

import java.util.*;
class Solution {
public String solution(String my_string) {
HashSet<Character> seen = new HashSet<>();
StringBuilder result = new StringBuilder();
for (char c : my_string.toCharArray()) {
if (!seen.contains(c)) {
result.append(c);
seen.add(c);
}
}
return result.toString();
}
}
HashSet은 중복을 허용하지 않는 데이터 구조이다. 이 문제에서 사용하면 쉽게 풀 수 있다.

import java.util.Arrays;
class Solution {
public int solution(int[] sides) {
int answer = 0;
Arrays.sort(sides);
if (sides[2] < sides[0] + sides[1]) {
answer = 1;
} else {
answer = 2;
}
return answer;
}
}