티스토리 뷰
https://programmers.co.kr/learn/courses/30/lessons/12935
코딩테스트 연습 - 제일 작은 수 제거하기
정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> arr) {
vector<int> answer;
if(arr.size() == 1) {
answer.push_back(-1);
}
else{
int smallest = arr[0];
for (int i = 1; i < arr.size(); i++)
smallest = min(smallest, arr[i]);
for (int i = 0; i < arr.size(); i++)
if(arr[i] != smallest) answer.push_back(arr[i]);
}
return answer;
}
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 가운데 글자 가져오기 : C++ (0) | 2021.08.11 |
---|---|
[프로그래머스] 최대공약수와 최소공배수 : C++ (0) | 2021.08.11 |
[프로그래머스] 하샤드 수 : C++ (0) | 2021.08.11 |
[프로그래머스] 행렬의 덧셈 : C++ (0) | 2021.08.11 |
[프로그래머스] 콜라츠 추측 : C++ (0) | 2021.08.11 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Open API
- 넥사크로
- HeidiSQL
- svn
- 인턴
- 스프링
- 스프링부트
- 오라클
- JVM
- 환경설정
- C++
- SQL
- 부트스트랩
- Java
- 프로그래머스
- Thymeleaf
- 개발용어
- 이클립스
- CSS
- 데이터베이스
- 백준
- 네트워크
- 국비교육
- JSP
- CS
- C
- 오류
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함