[C++] 프로그래머스 숫자게임
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(vector A, vector B) { int answer = 0; sort(A.begin(), A.end()); sort(B.begin(), B.end()); int index = 0; for(int i = 0; i < B.size(); i++) { if(A[index] < B[i]) { index++; answer++; } } return answer; } 풀이 1. 낮은 순으로 정렬해준다. 2. A를 B로 하나씩 비교하면서 최대한 작은 수로 이길 수 있게 유도한다. 느낀점 탐욕적 풀이들은 웬만하면 다 쉽게 생각해야 쉽게 풀리는 것같다. 더 쉽게 생각해보자. https://school.prog..