Guest User

Untitled

a guest
Nov 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /*
  2. 프로그래머스 : 해시/완주하지 못한 선수
  3.  
  4. 문제 설명
  5. 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다.
  6. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수들의 이름이 담긴 배열 completion이 주어질 때, 완주하지 못한 선수의 이름을 return 하도록 solution 함수를 작성해주세요.
  7.  
  8. 제한사항
  9. 마라톤 경기에 참여한 선수의 수는 1명 이상 100,000명 이하입니다.
  10. completion의 길이는 participant의 길이보다 1 작습니다.
  11. 참가자의 이름은 1개 이상 20개 이하의 알파벳 소문자로 이루어져 있습니다.
  12. 참가자 중에는 동명이인이 있을 수 있습니다.
  13. */
  14.  
  15. import java.util.*;
  16. import java.util.stream.Collectors;
  17.  
  18. public class Solution {
  19. public String solution(String[] participant, String[] completion) {
  20. String answer = "";
  21. List<String> pList = Arrays.asList(participant).stream()
  22. .sorted()
  23. .collect(Collectors.toList());
  24. List<String> cList = Arrays.asList(completion).stream()
  25. .sorted()
  26. .collect(Collectors.toList());
  27.  
  28. boolean found = false;
  29. for(int i=0; i<cList.size(); i++) {
  30. if(!pList.get(i).equals(cList.get(i))) {
  31. answer = pList.get(i);
  32. found = true;
  33. break;
  34. }
  35. }
  36.  
  37. return found ? answer : pList.get(pList.size()-1);
  38. }
  39. }
Add Comment
Please, Sign In to add comment