!!!! | Easy && Best | C++ Solution | using sorting |
Intuition\n- sort the numbers\n- try to generate consecutive number greedily\n\n# Approach\nGreedy Approach\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- S
# Intuition\n- sort the numbers\n- try to generate consecutive number greedily\n\n# Approach\nGreedy Approach\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int getMaximumConsecutive(vector<int>& coins) {\n        int ans = 1;\n        sort(coins.begin(),coins.end());\n        for(int coin:coins){\n            if(coin > ans) break;\n            ans += coin;\n        }\n        return ans;\n    }\n};\n```
['C++']