//구글콘솔 광고 추가가

처음에 아무 생각 없이 정렬해서 가장 작은 수를 지워버렸는데 그런 문제가 아니였다. 배열 안에서 가장 작은 수만 제거 하면 된다. 이게 왜 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

+ Recent posts