아이스크림들의 가격들이 담긴 정수형 벡터와 사용할 수 있는 코인의 개수를 받는다.
가장 많은 아이스크림을 살 때 아이스크림의 개수를 구하는 문제
class Solution {
public:
int maxIceCream(vector<int>& costs, int coins) {
sort(costs.begin(), costs.end());
int result{0};
int length = costs.size();
for (int i = 0; i < length; i++)
{
if (coins < costs[i])
{
break;
}
coins -= costs[i];
result++;
}
return result;
}
};