일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- flask
- SseEmitter
- 항해99
- jQuery
- web
- spring
- bean
- programmers
- html
- Spring Security
- WIL
- jenkins
- javascript
- server send event
- DI
- real time web
- cookie
- python
- JWT
- google oauth
- JPA
- oauth
- Hibernate
- session
- Project
- 생명주기 콜백
- Stream
- hanghae99
- Java
- Anolog
Archives
- Today
- Total
끄적끄적 코딩일지
[Programmers]완주하지 못한 선수(난이도:★★★) 본문
https://programmers.co.kr/learn/courses/30/lessons/42576
코딩테스트 연습 - 완주하지 못한 선수
수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수
programmers.co.kr
import java.util.Arrays;
class Solution {
int i = 0;
public String solution(String[] participant, String[] completion) {
return solutionB(participant,completion);
}
// 효율성은 개망
public String solutionA(String[] participant,String[] completion){
for(i = 0 ; i < participant.length;i++){
int pCount = Arrays.stream(participant).filter(e->e.eqauls(praticipant[i])).count();
int cCount = Arrays.stream(completion).filter(e->e.equals(participant[i])).count();
if(pCount != cCount) {
return participant[i];
};
}
return null;
}
// 정렬후 다른 이름이 나온 시점 반환
public String solutionB(String[] participant,String[] completion){
Arrays.sort(participant);
Arrays.sort(completion);
String answer = participant[participant.length-1];
for(int i = 0 ; i <participant.length-1; i++){
if(!participant[i].equals(completion[i])){
return participant[i];
}
}
return null;
}
}
'알고리즘' 카테고리의 다른 글
[Programmers]자릿수 더하기(난이도:★★★) (0) | 2022.05.16 |
---|---|
[Programmers]이상한 문자 만들기(난이도:★★★) (0) | 2022.05.16 |
[Programmers]수박수박수박수박수?(난이도:★★★) (0) | 2022.05.16 |
[Programmers]서울에서 김서방 찾기(난이도:★★★) (0) | 2022.05.16 |
[Programmers]문자열 다루기 기본(난이도:★★★) (0) | 2022.05.16 |