class Solution {
public String solution(String[] seoul) {
String answer = "";
String str;
int idx = -1;
for (int i = 0; i < seoul.length; i++) {
str = seoul[i];
if (str.equals("Kim")) {
idx = i;
break;
}
}
answer = "김서방은 " + idx + "에 있다";
return answer;
}
}
다른 사람 코드 - String[] -> List로 변경
import java.util.Arrays;
import java.util.List;
class Solution {
public String solution(String[] seoul) {
String answer = "";
String str;
int idx = -1;
List<String> list = Arrays.asList(seoul);
idx = list.indexOf("Kim");
answer = "김서방은 " + idx + "에 있다";
return answer;
}
}
'프로그래머스' 카테고리의 다른 글
프로그래머스 - 모의고사 (0) | 2019.01.07 |
---|---|
프로그래머스 - 짝수와 홀수 (0) | 2019.01.07 |
프로그래머스 - 수박수박수박수박수박수? (0) | 2019.01.07 |
프로그래머스 - 두 정수 사이의 합 (0) | 2019.01.05 |
프로그래머스 - 완주하지 못한 선수 (0) | 2019.01.05 |