-
[programmers] 제일 작은 수 제거하기 / C++공부/PS (programmers) 2022. 7. 19. 23:02
https://school.programmers.co.kr/learn/courses/30/lessons/12935
#include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; vector<int> solution(vector<int> arr) { vector<int> answer; if(arr.size() == 1) answer.push_back(-1); else { int minNum = *min_element(arr.begin(), arr.end()); //cout << "minNum = " << minNum << "\n"; for(int i=0; i<arr.size(); i++) { if(arr[i] != minNum) { answer.push_back(arr[i]); } } } return answer; }
vector 원소 중 최소값/최대값 찾기
#include <algorithm> #include <vector> vector <int> vec; int minNum = *min_element(vec.begin(), vec.end()); // 최소값 int maxNum = *max_element(vec.begin(), vec.end()); // 최대값
'공부 > PS (programmers)' 카테고리의 다른 글
[programmers] 폰켓몬 / C++ (0) 2022.07.27 [programmers] 이상한 문자 만들기 / C++ (0) 2022.07.20 [programmers] 소수 만들기 / C++ (0) 2022.07.19 [programmers] 두 개 뽑아서 더하기 / C++ (0) 2022.07.19 [programmers] 프린터 / C++ (0) 2022.05.18