Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYEWON CHOI : PROGRAMMERS Lv1 로또의 최고 순위와 최저 순위 #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hiii456
Copy link
Contributor

@hiii456 hiii456 commented Dec 1, 2021

Programmers - 로또의 최고 순위와 최저 순위

풀이

lottos 배열의 인덱스가 0인 경우와 0이 아닌 경우를 나누어서 문제를 풀었습니다.
0인 경우 zero를 count 해주었고, 아닌 경우에는 win_nums 배열과 비교하여 맞으면 match를 count해준뒤 break해주어 다음 인덱스로 넘어가며 문제를 구하였습니다.

소스코드

class Solution {
	    public int[] solution(int[] lottos, int[] win_nums) {
	        int[] answer = new int[2];
	        int zero = 0;
	        int match = 0;
	        for(int i : lottos){
	            // 0이 아닌 경우에만 win_nums 탐색 
	            if(i==0){
	                zero++;
	            }else{
	                for(int j : win_nums){
	                    if(i==j){
	                        match++;
	                        break;
	                    }
	                }
	            }
	        }
	        
	        
	        answer[0] = match !=0 ? 7-match-zero : (zero !=0 ? 7-zero : 6);
	        answer[1] = match !=0 ? 7-match : 6;
	        
	        return answer;
	    }
	}

결과

|정확성|테스트|
|테스트 1 | 통과 (0.02ms, 79.3MB)|
|테스트 2 | 통과 (0.01ms, 73.5MB)|
|테스트 3 | 통과 (0.02ms, 73.6MB)|
|테스트 4 | 통과 (0.01ms, 78.5MB)|
|테스트 5 | 통과 (0.01ms, 73.3MB)|
|테스트 6 | 통과 (0.01ms, 76.4MB)|
|테스트 7 | 통과 (0.01ms, 73.9MB)|
|테스트 8 | 통과 (0.01ms, 77.5MB)|
|테스트 9 | 통과 (0.02ms, 78.8MB)|
|테스트 10| 통과 (0.02ms, 75.8MB)|
|테스트 11 | 통과 (0.02ms, 76.4MB)|
|테스트 12 | 통과 (0.03ms, 73.4MB)|
|테스트 13 | 통과 (0.01ms, 74.8MB)|
|테스트 14 | 통과 (0.01ms, 67.9MB)|
|테스트 15 | 통과 (0.02ms, 77.8MB)|

@hiii456 hiii456 added the Impl Implementation label Dec 1, 2021
@hiii456 hiii456 self-assigned this Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impl Implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant