문제
내 풀이
class Solution {
public String[] solution(String[] quiz) {
String[] answer = {};
answer = new String[quiz.length];
for (int i = 0 ; i < quiz.length ; i ++){
String[] str = quiz[i].split(" ");
if((str[1].equals("+"))){
if(((Integer.parseInt(str[0])+Integer.parseInt(str[2]))==Integer.parseInt(str[4]))){
answer[i]="O";
}else{
answer[i]="X";
}
}else if(str[1].equals("-")){
if(((Integer.parseInt(str[0])-Integer.parseInt(str[2]))==Integer.parseInt(str[4]))){
answer[i]="O";
}else{
answer[i]="X";
}
}
}
return answer;
}
}
다른 사람 풀이
class Solution {
public String[] solution(String[] quiz) {
for(int i=0; i<quiz.length; i++){
String[] text = quiz[i].split(" ");
int result = Integer.parseInt(text[0]) + ( Integer.parseInt(text[2]) * ( text[1].equals("+") ? 1:-1) );
quiz[i] = result == Integer.parseInt(text[4])? "O": "X";
}
return quiz;
}
}