일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Project
- python
- 항해99
- google oauth
- cookie
- Hibernate
- WIL
- hanghae99
- Java
- jQuery
- SseEmitter
- session
- Spring Security
- JPA
- Anolog
- 생명주기 콜백
- Stream
- programmers
- DI
- jenkins
- server send event
- flask
- html
- spring
- web
- JWT
- bean
- oauth
- javascript
- real time web
Archives
- Today
- Total
끄적끄적 코딩일지
[Programmers]완주하지 못한 선수(난이도:★★★) 본문
https://programmers.co.kr/learn/courses/30/lessons/42576
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 |