728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12935#
코딩테스트 연습 - 제일 작은 수 제거하기
정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1
programmers.co.kr
using System.Linq;
public class Solution {
public int[] solution(int[] arr) {
int size = (arr.Length) > 0 ? arr.Length - 1 : 1;
int[] answer = new int[size];
if (size == 1)
{
answer[0] = -1;
return answer;
}
else
{
int temp_min = arr.Min(), j = 0;
for (int i = -1; ++i < arr.Length;)
if (arr[i] != temp_min) answer[j++] = arr[i];
}
return answer;
}
}
테스트 케이스 2번이 좀 이상한 거 같구먼..
반응형
'프로그래머스_C# > Level_1' 카테고리의 다른 글
[프로그래머스 C#] 정수 내림차순으로 배치하기 (0) | 2021.08.11 |
---|---|
[프로그래머스 C#] 정수 제곱근 판별 (0) | 2021.08.01 |
[프로그래머스 C#] 짝수와 홀수 (0) | 2021.07.17 |
[프로그래머스 C#] 최대공약수와 최소공배수 (0) | 2021.07.10 |
[프로그래머스 C#] 콜라츠 추측 (0) | 2021.07.03 |