-
프로그래머스 - 제일 작은 수 제거하기 [자바]Algorithms/- 프로그래머스 2022. 2. 10. 22:09
- 문제 링크 : 제일 작은 수 제거하기
정답(Solution)
class Solution { public int[] solution(int[] arr) { if(arr.length == 1){ return new int[]{-1}; } int[] answer = new int[arr.length - 1]; int min = Integer.MAX_VALUE; int idx = 0; for(int i=0; i<arr.length; i++){ if(arr[i] < min){ min = arr[i]; idx = i; } } int idx2 = 0; for(int i=0; i<answer.length; i++){ if(i == idx){ idx2++; } answer[i] = arr[idx2]; idx2++; } return answer; } }
분석
- 단순 for문 문제
- index만 잘 지정해주면 어렵지 않음 문제이다.
반응형