Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - Python
- redux-saga
- C++
- 알고리즘
- axios
- react-router
- redux-toolkit
- programmers
- 이코테
- 매일메일
- json-server
- 리액트
- 프로그래머스
- SW
- react
- JavaScript
- 자바
- 코딩테스트합격자되기
- sw expert academy
- useDispatch
- redux
- java
- Algorithm
- createSlice
- Get
- 테코테코
- 항해99
- maeil-mail
- react-redux
- 항해플러스
                            Archives
                            
                        
                          
                          - Today
- Total
Binary Journey
[프로그래머스] 로또의 최고 순위와 최저 순위 본문
반응형
    
    
    
  
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

풀다 보면 아마 계속 통과되지 않는 테스트 케이스가 나올텐데 그것은 모든 숫자가 꽝일 때인 테스트 케이스이다.
모든 수가 0일 때만이 아니라 다 틀렸을 때 완전 꽝일 때까지 고려해야 한다.
** Javascript
function solution(lottos, win_nums) {
    const numbers = lottos.filter(num => win_nums.includes(num) || num === 0);
    const maxRank = numbers.every(num => !win_nums.includes(num) && num > 0) ? 6 : 7 - numbers.length;
    const minRank = (numbers.every(num => num === 0)) ? 6 : 7 - numbers.filter(num => num > 0).length;
    return [maxRank, minRank];
}
** Python
def solution(lottos, win_nums):
    new_lottos = [ l for l in lottos if l in win_nums]
    zeros = lottos.count(0)
    maximum = min(6, 7 - (len(new_lottos) + zeros))
    minimum = min(6, 7 - len(new_lottos))
    return [maximum, minimum]반응형
    
    
    
  '프로그래머스 > level 1' 카테고리의 다른 글
| [프로그래머스] 문자열 내 p와 y의 개수 (0) | 2021.09.07 | 
|---|---|
| [프로그래머스] 내적 (0) | 2021.09.01 | 
| [프로그래머스] 문자열 다루기 기본 (0) | 2021.08.30 | 
| [프로그래머스][위클리챌린지] 4주차 직업군 추천하기 (0) | 2021.08.30 | 
| [프로그래머스] 실패율 (0) | 2021.08.23 | 
 
                   
                  