[프로그래머스] 로또의 최고 순위와 최저 순위 Level1 (자바,java)

[프로그래머스] 로또의 최고 순위와 최저 순위 Level1 (자바,java)

- 풀이

lottos, win_nums의 배열길이가 6이기 때문에 2중포문을 사용해도 효율성 문제는 없다.

i를 lottos로 잡고 j를 win_nums로 잡아 lottos[i]가 0이었을때 카운트하고, 두배열을 비교하여 같을때를 카운트한다.

테스트 케이스14는 모두 일치하지 않을때이므로 예외 처리만 해준다.

import java.util.*; class Solution { public int[] solution(int[] lottos, int[] win_nums) { int cnt=0, cnt2=0; for (int i=0; i<6; i++) { int tmp=lottos[i]; if(tmp==0) { cnt2++; continue; } for (int j=0; j<6; j++) { if(tmp==win_nums[j]) cnt++; } } int[] answer = new int[2]; answer[0]=7-cnt-cnt2; answer[1]=7-cnt; if(answer[0]==7) answer[0]=6; if(answer[1]==7) answer[1]=6; return answer; } }

from http://rotomoo.tistory.com/29 by ccl(A) rewrite - 2021-11-05 20:01:46