코딩테스트_c#/프로그래머스
프로그래머스 ) 코딩테스트 연습 - 숫자게임 Level.3_C#
노년인생
2024. 2. 19. 15:33
728x90
반응형
level 3 문제는 아닌 것 같은데 내가 편법으로 푼건가 고민되는 문제. +3점
sort로 정렬한 다음 A랑 B랑 같은 값을 내게 되면 B가 자기꺼에서 더 큰 수를 내밀어야 됨.
테스트 케이스 추가
A | B |
{1,1,2,5,8} | {1,1,1,2,3} |
숫자게임 문제
내 코드
using System;
//+3
public class Solution {
public int solution(int[] A, int[] B) {
bool[] C = new bool[B.Length];
int answer = -1;
int num = 0;
Array.Sort(A);
Array.Sort(B);
for(int i = 0; i < A.Length; i++)
{
for (int j= num; j < B.Length; j++)
{
if (A[i] < B[j])
{
if (!C[j])
{
answer++;
C[j] = true;
num = j;
break;
}
}
}
}
if (answer == -1)
answer = 0;
else
answer += 1;
return answer;
}
}
728x90
반응형