일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- web
- Spring Security
- SseEmitter
- python
- spring
- 생명주기 콜백
- JPA
- jenkins
- session
- programmers
- Project
- bean
- real time web
- jQuery
- Java
- WIL
- JWT
- DI
- Anolog
- oauth
- server send event
- cookie
- Hibernate
- Stream
- html
- flask
- javascript
- 항해99
- hanghae99
- google oauth
Archives
- Today
- Total
끄적끄적 코딩일지
[Programmers]로또의 순위(난이도:★★★★) 본문
https://programmers.co.kr/learn/courses/30/lessons/77484
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
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 |