class Solution {
public int[] solution(String route) {
int east = 0;
int north = 0;
int[] answer = new int [2];
for(int i=0; i<route.length(); i++){
switch(route.charAt(i)){
case 'N':
north++;
break;
case 'S':
north--;
break;
case 'E':
east++;
break;
case 'W':
east--;
break;
}
}
answer[0] = east;
answer[1] = north;
return answer;
}
}
'코딩테스트 > lv0' 카테고리의 다른 글
[프로그래머스 코딩테스트] java Lv.0 나이 계산 (PCCE 기출 문제 3번) (0) | 2024.06.26 |
---|---|
[프로그래머스 코딩테스트] java Lv.0 저축 (PCCE 기출 문제 4번) (0) | 2024.06.26 |
[프로그래머스 코딩테스트] java Lv.0 가채점 (PCCE 기출문제 6번) (0) | 2024.06.26 |
[프로그래머스 코딩테스트] java Lv.0 가습기(PCCE 기출문제 7번) (0) | 2024.06.26 |
[프로그래머스 코딩테스트] java Lv.0 문자열 출력하기 (0) | 2024.06.26 |