leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0735.cpp (470B)
0 class Solution { 1 public: 2 vector<int> asteroidCollision(vector<int> &asteroids) { 3 vector<int> st; 4 for (int aster : asteroids) { 5 while (!st.empty() && st.back() > 0 && st.back() < -aster) 6 st.pop_back(); 7 if (st.empty() || aster > 0 || st.back() < 0) 8 st.push_back(aster); 9 else if (aster < 0 && st.back() == -aster) 10 st.pop_back(); 11 } 12 return st; 13 } 14 };