2126.cpp (331B)
1 class Solution { 2 public: 3 bool asteroidsDestroyed(int mass, vector<int> &asteroids) const { 4 sort(begin(asteroids), end(asteroids)); 5 6 for (const int num : asteroids) { 7 if (num > mass) return false; 8 if (mass > 1e5) break; 9 mass += num; 10 } 11 12 return true; 13 } 14 };