일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- session
- cookie
- html
- WIL
- JPA
- Anolog
- web
- jenkins
- Hibernate
- google oauth
- SseEmitter
- jQuery
- DI
- spring
- bean
- Spring Security
- JWT
- python
- hanghae99
- programmers
- 항해99
- 생명주기 콜백
- real time web
- oauth
- server send event
- flask
- javascript
- Stream
- Java
Archives
- Today
- Total
끄적끄적 코딩일지
[Programmers]로또의 순위(난이도:★★★★) 본문
https://programmers.co.kr/learn/courses/30/lessons/77484
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
return solutionA(lottos,win_nums);
}
public int[] solutionA(int[] lottos,int[] win_nums){
int zeros = 0;
int matches = 0;
// 0의 개수 count
for(int i = 0 ; i < 6; i++){
if(lottos[i] == 0){
zeros++;
continue;
}
// 0이 아니라면 win_nums에 있는지 확인
for(int j = 0; j < 6; j++){
if(lottos[i] == win_nums[j]){
matches++;
break;
}
}
}
// 등수 계산
int max = 7 - (zeros+matches);
int min = 7 - matches;
max = Math.min(6,max);
min = Math.min(6,min);
return new int[]{max,min};
}
}
'알고리즘' 카테고리의 다른 글
[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 |