https://school.programmers.co.kr/learn/courses/30/lessons/77484
public class Solution
{
public static int[] solution(int[] lottos, int[] win_nums)
{
int sameValue = 0;
int zeroValue = 0;
int[] rank = new int[7] { 6, 6, 5, 4, 3, 2, 1 };
for (int i = 0; i < lottos.Length; i++)
{
if (lottos[i] == 0)
{
zeroValue++;
continue;
}
for (int j = 0; j < win_nums.Length; j++)
{
if (lottos[i] == win_nums[j])
{
sameValue++;
break;
}
}
}
int min = sameValue;
int max = min + zeroValue;
int[] answer = new int[2] { rank[max], rank[min] };
return answer;
✍ lottos에서 0이 들어가는 만큼 zeroValue에 값을 할당해주고 win_nums에는 lottos와 같은 값이 있는지 대조하여 sameValue에 할당해준다.
✍ lottos와 win_nums에 같은 값이 들어가 있다면 min에 sameValue를 할당해준다.
✍ max에는 min + zeroValue를 할당해준다.
✍ 위와 같이 선언했다면 min = 2(최저순위), max = 4(최고순위)이다.
✍ 이제 rank 배열의 Index값을 출력하면된다.
using System;
public class Solution {
public int[] solution(int[] lottos, int[] win_nums)
{
int[] answer;
int a = 7;
int b = 7;
for (int i = 0; i < lottos.Length; i++)
{
if (lottos[i] == 0) a--;
else if (Array.Exists(win_nums, x => x == lottos[i]))
{
a--; b--;
}
}
if (a == 7) a = 6;
if (b == 7) b = 6;
answer = new int[2] {a, b};
return answer;
}
}
using System;
using System.Linq;
public class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int right = 0;
int zeroCount =0;
for(int i=0; i<lottos.Length; i++)
{
if(lottos[i]==0)
{
zeroCount++;
}
if(lottos.Contains(win_nums[i]))
{
right++;
}
}
int MaxCollect = zeroCount+right;
int MinCollect = right;
if(MinCollect==0) MinCollect++;
if(MaxCollect==0) MaxCollect++;
int[] answer = new int[] {7-MaxCollect,7-MinCollect};
return answer;
}
}