Programmers - 완주하지 못한 선수

문제 링크

screenshot1 screenshot2

Java 풀이

import java.util.Arrays;

class Solution {    
    public String solution(String[] participant, String[] completion) {
        
        Arrays.sort(participant);
        Arrays.sort(completion);
                
        int index = 0;
        int length = completion.length;
        
        for(; index < length; index++){
            if( !completion[index].equals(participant[index]) ){
                return participant[index];
            }
        }
        return participant[index];
        
    }
}

Javascript 풀이

function solution(participant, completion) {
    
    Array.prototype.sort.call(participant);
    Array.prototype.sort.call(completion);
    var index = 0;
    var length = completion.length;
    for(; index < length; index++){
        if( completion[index] !== participant[index] ){
            return participant[index];
        }
    }
    return participant[index];
}