반응형

 

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

 

 

** Javascript

 

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

 

 

 

** Python

 

def solution(participant, completion):
    participant.sort()
    completion.sort()
    for i in range(len(completion)):
        if participant[i] != completion[i]:
            return participant[i]
    return participant[len(participant)-1]

 

 

 

** Java

 

import java.util.*;
class Solution {
    public String solution(String[] participant, String[] completion) {
        Arrays.sort(participant);
        Arrays.sort(completion);
        for (int i = 0; i < completion.length; i++) {
            if (!Objects.equals(participant[i], completion[i])) return participant[i];
        }
        return participant[participant.length-1];
    }
}

 

 

반응형

+ Recent posts