//구글콘솔 광고 추가가

처음에 아무 생각 없이 정렬해서 가장 작은 수를 지워버렸는데 그런 문제가 아니였다. 배열 안에서 가장 작은 수만 제거 하면 된다. 이게 왜 9점이나 줬을까.


제일 작은 수 제거하기 문제

내 코드
using System;
using System.Collections.Generic;
//+9
public class Solution {
    public int[] solution(int[] arr) {
        int min = arr[0];
        List<int> answer = new List<int>(arr);
        if (arr.Length == 1) answer.Add(-1);
        else
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if(min > arr[i]) min = arr[i];
            }
        }
        answer.Remove(min);
        return answer.ToArray();
    }
}

 

728x90
겹치는 선분의 길이 문제

내 코드
using System;
using System.Linq;
public class Solution {
    public int solution(int[,] lines) {
        int answer = 0;
        int [] a = { lines[0, 0], lines[1, 0], lines[2, 0] }; 
        int [] b = { lines[0, 1], lines[1, 1], lines[2, 1] };
        int aMin = a.Min(); 
        int bMax = b.Max();
        for (int k = aMin; k < bMax; k++) 
        {
            int count = 0;
            if( k >= a[0] && k + 1 <= b[0])
            {
                count++;
            }
            if (k >= a[1] && k + 1 <= b[1])
            {
                count++;
            }
            if (k >= a[2] && k + 1 <= b[2])
            {
                count++;
            }
            if(count >= 2)
            {
                answer++;
            }
        }
        return answer;
    }
}
728x90

+ Recent posts