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

21.05.07 - [PG - 2021 Dev Matching] 로또의 최고 순위와 최저 순위 #61

Closed
suhyunsim opened this issue May 9, 2021 · 0 comments
Assignees
Labels
lv.1 프로그래머스 - level 1 성공 맞은 문제

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented May 9, 2021

문제

핵심 아이디어

  • winCount와 zeroCount를 확인하고 최대 최소를 미리 만들어놓은 배열에서 찾기

어려운 점, 실수

풀이

package main.java.com.poogle.PG.Q77484;

import java.util.HashSet;
import java.util.Set;

//로또의 최고 순위와 최저 순위
public class Solution {
    public static int[] solution(int[] lottos, int[] win_nums) {
        int winCnt = 0;
        int zeroCnt = 0;

        int[] level = {6, 6, 5, 4, 3, 2, 1};
        Set<Integer> set = new HashSet<>();

        for (int i : win_nums) {
            set.add(i);
        }
        for (int i : lottos) {
            if (i == 0) zeroCnt++;
            if (set.contains(i)) winCnt++;
        }
        return new int[] {level[winCnt + zeroCnt], level[winCnt]};
    }

    public static void main(String[] args) {
        int[] lottos = {5, 2, 0, 0, 4};
        int[] win_nums = {1, 4, 2, 5, 3};
        solution(lottos, win_nums);
    }
}
@suhyunsim suhyunsim self-assigned this May 9, 2021
@suhyunsim suhyunsim changed the title 21.05.07 - [PG] 로또의 최고 순위와 최저 순위 21.05.07 - [PG - 2021 Dev Matching] 로또의 최고 순위와 최저 순위 May 9, 2021
@suhyunsim suhyunsim added lv.1 프로그래머스 - level 1 성공 맞은 문제 labels May 15, 2021
@suhyunsim suhyunsim added this to the 5월 1주 차 milestone May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.1 프로그래머스 - level 1 성공 맞은 문제
Projects
None yet
Development

No branches or pull requests

1 participant