내 답안
class Solution {
public String solution(int[] numLog) {
String answer = "";
for(int i=1; i<numLog.length; i++){
if(numLog[i] - numLog[i-1] ==1){
answer += "w";
}else if(numLog[i] - numLog[i-1] == -1){
answer += "s";
}else if(numLog[i] - numLog[i-1] == 10){
answer += "d";
}else{
answer += "a";
}
}
return answer;
}
}
Java
복사
다른 사람 풀이법
class Solution {
public String solution(int[] numLog) {
String answer = "";
for(int i=1; i<numLog.length; i++){
int j = numLog[i-1] - numLog[i];
switch(j){
case -1 : answer+='w'; break;
case 1 : answer+='s'; break;
case -10 : answer+='d'; break;
case 10 : answer+='a'; break;
}
}
return answer;
}
}
Java
복사
class Solution {
public String solution(int[] numLog) {
String answer = "";
int temp = numLog[0];
for(int i=1; i<numLog.length; i++){
switch(numLog[i]-temp) {
case 1:
answer += "w";
break;
case -1:
answer += "s";
break;
case 10:
answer += "d";
break;
case -10:
answer += "a";
break;
}
temp = numLog[i];
}
return answer;
}
}
Java
복사