Sorting , Easy C++ Beats 98% ✅✅
Approach\n Describe your approach to solving the problem. \n\nThe smallest asteroid will hit the planet if the mass of the smallest\nasteroid is greater than th
# Approach\n<!-- Describe your approach to solving the problem. -->\n```\nThe smallest asteroid will hit the planet if the mass of the smallest\nasteroid is greater than that of the planet, so it is not possible to \ndestroy all asteroids.\n```\n# Complexity\n- Time complexity:O(N*Log(N))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool asteroidsDestroyed(int m, vector<int>& a) {\n        sort(a.begin(),a.end());\n        long long sum = m;\n        for(int i = 0;i<a.size();i++)\n        {\n            if(a[i]>sum) return false;\n            sum+=a[i];\n        }\n        return true; \n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/b4f65d2d-3b1f-46fc-b3bb-b313f2cdd057_1689833615.7635784.jpeg)\n
['Sorting', 'C++']