leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0735.cpp (470B)


      1 class Solution {
      2   public:
      3     vector<int> asteroidCollision(vector<int> &asteroids) {
      4         vector<int> st;
      5         for (int aster : asteroids) {
      6             while (!st.empty() && st.back() > 0 && st.back() < -aster)
      7                 st.pop_back();
      8             if (st.empty() || aster > 0 || st.back() < 0)
      9                 st.push_back(aster);
     10             else if (aster < 0 && st.back() == -aster)
     11                 st.pop_back();
     12         }
     13         return st;
     14     }
     15 };