[Programmers] level 1 - 서울에서 김서방 찾기

Lynn·2021년 2월 11일
0

Algorithm

목록 보기
29/43
post-thumbnail

👩🏻‍💻 문제

👩🏻‍💻 정답 코드

class Solution {
    public String solution(String[] seoul) {
        String answer = "";
        int i;
        for (i=0; i<seoul.length; i++){
            if (seoul[i].equals("Kim")) break;
        }
        answer = "김서방은 "+i+"에 있다";
        return answer;
    }
}

seoul 배열을 처음부터 돌면서 seoul[i].equals("Kim")으로 비교하고 index를 찾으면 break 시켰다. 이렇게 푸는 게 최선인가...?

profile
wanderlust

0개의 댓글