Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created April 27, 2020 07:15
Show Gist options
  • Save DongguemYoo/13c045de57f166f6096142f880eee340 to your computer and use it in GitHub Desktop.
Save DongguemYoo/13c045de57f166f6096142f880eee340 to your computer and use it in GitHub Desktop.
코딩테스트 체육복
using System;
public class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int answer = 0;
int[] t_lost = new int[n];
int[] t_reserve = new int[n];
for(int i=0;i<n;i++)
{
t_lost[i] =0;
t_reserve[i] = 0;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<lost.Length;j++)
{
if(i+1 == lost[j])
t_lost[i] = lost[j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<reserve.Length;j++)
{
if(i+1 == reserve[j])
{
if(t_lost[i] != 0)
{
t_lost[i] = 0;
t_reserve[i] =0;
}else
t_reserve[i] = reserve[j];
}
}
}
//return t_lost[0];
for(int i=0;i<n;i++)
{
if(t_lost[i]==0)
answer++;
else
{
//도둑맞은 친구
//가장 체격이 작은 친구
if(i==0)
{
if(t_reserve[i+1] !=0)
{
answer++;
t_reserve[i+1] =0;
continue;
}
}
//가장 체격이 큰 친구
if(i==n-1)
{
if(t_reserve[i-1] !=0)
{
answer++;
t_reserve[i-1] =0;
continue;
}
}
if(0<i && i<n-1)
{
//양쪽에서 도움을 받을 수 있는 인덱스
//뒤쪽에서 도움을 준다
if(t_reserve[i-1]!=0)
{
answer++;
t_reserve[i-1] = 0;
continue;
}
//앞쪽에서 도움을 준다
if(t_reserve[i+1] != 0)
{
answer++;
t_reserve[i+1] = 0;
continue;
}
}
}
}
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment