반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- codeup 1020 자바
- 빅분기실기
- 가운데 글자 가져오기 python
- 최소 스패닝 트리
- 프로그래머스 가운데 글자 가져오기 python
- codeup 1020 java
- 가운데 글자 가져오기 자바
- 청년 AI Big Data 아카데미 13기
- docker 삭제
- 가운데 글자 가져오기 파이썬
- 프로그래머스 나누어 떨어지는 숫자 배열 파이썬
- 최단 경로 알고리즘
- 나누어 떨어지는 숫자 배열 java
- 핸즈온 머신러닝
- 프로그래머스 가운데 글자 가져오기 파이썬
- 가운데 글자 가져오기 java
- 트리의 지름 자바
- m1 docker install
- 프로그래머스 가운데 글자 가져오기 자바
- 나누어 떨어지는 숫자 배열 python
- 트리의 지름 java
- docker 완전 삭제
- 코드업 1020 java
- docker remove
- 프로그래머스 나누어 떨어지는 숫자 배열 자바
- 빅데이터분석기사
- 최소 스패닝 트리 자바
- 청년 Ai Big Data 아카데미
- 코드업 1020 자바
- m1 docker
Archives
- Today
- Total
NineTwo meet you
[프로그래머스/파이썬/자바] 제일 작은 수 제거하기 본문
반응형
문제 & 제한사항 & 예제
더보기
문제 설명
정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요.
단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요.
예를들어 arr이 [4,3,2,1]인 경우는 [4,3,2]를 리턴 하고, [10]면 [-1]을 리턴 합니다.
제한 조건
- arr은 길이 1 이상인 배열입니다.
- 인덱스 i, j에 대해 i ≠ j이면 arr[i] ≠ arr[j] 입니다.
입출력 예
arr | return |
[4,3,2,1] | [4,3,2] |
[10] | [-1] |
코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int[] solution(int[] arr) { | |
int[] answer; | |
if(arr.length == 1){ | |
answer = new int[1]; | |
answer[0] = -1; | |
}else{ | |
answer = new int[arr.length-1]; | |
int minIndex = 0; | |
for(int i = 0; i < arr.length; i++){ | |
if(arr[minIndex] > arr[i]){ | |
minIndex = i; | |
} | |
} | |
int index = 0; | |
for(int i = 0; i < arr.length; i++){ | |
if(i == minIndex){ | |
continue; | |
}else{ | |
answer[index] = arr[i]; | |
index++; | |
} | |
} | |
} | |
return answer; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(arr): | |
if len(arr) != 1: | |
arr.remove((min(arr))) | |
return arr | |
else: | |
return [-1] |
반응형
'프로그래밍 문제 > 프로그래머스' 카테고리의 다른 글
[프로그래머스/파이썬/자바] 핸드폰 번호 가리기 (0) | 2020.08.22 |
---|---|
[프로그래머스/파이썬/자바] 평균 구하기 (0) | 2020.08.22 |
[프로그래머스/파이썬/자바] 자릿수 더하기 (0) | 2020.08.22 |
[프로그래머스/파이썬/자바] 자연수 뒤집어 배열로 만들기 (0) | 2020.08.22 |
[프로그래머스/파이썬/자바] 이상한 문자 만들기 (0) | 2020.08.21 |