|| shark tank approach || cpp || priority_queue ||
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#include <queue>\n#include <string>\n#include <vector>\n#include <algorithm>\n\nclass Solution {\npublic:\n    string clearStars(string s) {\n        // Define the priority queue correctly\n        priority_queue<char, vector<char>, greater<char>> pq;\n        \n        for (int i = 0; i < s.size(); ++i) {\n            if (s[i] == \'*\') {\n                // Remove the current \'*\'\n                s.erase(i, 1);\n                // Decrease index to check the new character at the same position\n                --i;\n\n                // Find the closest previous character that is not \'*\'\n                int j = i;\n                while (j >= 0 && (s[j] == \'*\' || s[j] != pq.top())) {\n                    --j;\n                }\n\n                // Remove the character if found\n                if (j >= 0 && s[j] == pq.top()) {\n                    s.erase(j, 1);\n                    --i; // Adjust the index again after erasing\n                }\n\n                if (!pq.empty()) {\n                    pq.pop();\n                }\n            } else {\n                pq.push(s[i]);\n            }\n        }\n\n        return s;\n    }\n};\n\n```
['C++']