Posted on

Description

Submission

class Solution {
public:
    int maxIceCream(vector<int>& costs, int coins) {
        sort(costs.begin(), costs.end());

        int ret = 0;
        for(int i = 0; i < costs.size() && coins >= costs[i]; ++i) {
            coins -= costs[i];
            ++ret;
        }

        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *