euisblue
77484. 로또의 최고 순위와 최저 순위

Level 1 로또의 최고 순위와 최저 순위

시간 복잡도: **O(36)**인데... O(1)이라고 하기는 애매하다..

1#include <bits/stdc++.h> 2using namespace std; 3 4vector<int> solution(vector<int> lottos, vector<int> win_nums) { 5 int rank[] = {6, 6, 5, 4, 3, 2, 1}; 6 int score = 0; 7 int lost = 0; 8 9 for(int i=0; i<6; ++i) { 10 if(lottos[i]==0) { 11 ++lost; 12 continue; 13 } 14 15 for(int j=0; j<6; ++j) { 16 if(lottos[i] == win_nums[j]) { 17 ++score; 18 break; 19 } 20 } 21 } 22 23 vector<int> answer(2); 24 answer[0] = rank[score+lost]; 25 answer[1] = rank[score]; 26 27 return answer; 28}

보이지 않는 숫자가 뭐든 상관없이 현재 당첨된 개수가 최저 순위가 된다. 반대로 보이지 않는 숫자가 전부 당첨일 수도 있으니 0의 개수를 구해서 현재 당첨된 숫자에 더해주면 된다.