id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string& s) {\n stack<char> st;\n\n for (char c : s)\n {\n if (c == '*')\n {\n if (!st.empty())\n {\n st.pop();\n }\n }\n else\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(const string& s) {\n stack<char> sona;\n for (char ch:s) {\n if (ch != '*') {sona.push(ch);} \n else if (!sona.empty()){sona.pop();}}\n string sonali;\n while (!sona.empty()) {\n sonali.push_back(... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(const string& s) {\n stack<char> sona;\n for (char ch:s) {\n if (ch != '*') {sona.push(ch);} \n else if (!sona.empty()){sona.pop();}}\n string sonali;\n while (!sona.empty()) {\n sonali.push_back(... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\tint writeIndex=0;\n\tfor (int readIndex=0; readIndex<s.size(); readIndex++) {\n\t\tif (s[readIndex]=='*') {\n\t\t\twriteIndex--;\n}\nelse {\n\ts[writeIndex++] = s[readIndex];\n}\n\n}\ns.resize(writeIndex);\nreturn s;\n }\n};",
"memory": ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(const string& s) {\n stack<char> sona;\n for (char ch:s) {\n if (ch != '*') {sona.push(ch);} \n else if (!sona.empty()){sona.pop();}}\n string sonali;\n while (!sona.empty()) {\n sonali.push_back(... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n for (int i = 0; i < s.size(); ++i) {\n if (s[i] == '*') {\n s.erase(i - 1, 2);\n i-= 2;\n }\n }\n \n return s;\n }\n};",
"memory": "24641"
} |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int i = 0;\n // int n = s.length();\n while(i < s.length()){\n if(s[i] == '*'){\n s = s.erase(i-1,2);\n i--;\n }\n else i++;\n }\n return s;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int l = s.length();\n for (int i = 0; i < l; i++) {\n if (s[i+1] == '*') {\n s.erase(i, 2);\n l -= 2;\n i -= 2;\n }\n }\n return s;\n }\n};",
"... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n for(int i = 0; i < s.length(); i++) {\n if(s[i] == '*') {\n if(i > 0) { \n s.erase(i - 1, 2); \n i -= 2;\n } else { \n s.erase(i, 1); \n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int i = 0;\n int count = 0;\n while(i < s.size())\n {\n while(s[i] == '*' && i < s.size())\n {\n count ++; \n i ++;\n // s.erase(i, 1);\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "static auto _ = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return true;\n}();\n\n\nclass Solution {\npublic:\n string removeStars(string s) {\n\n for(int i = 0; i < s.size(); i ++){\n if(s[i] == '*') { s.erase(i-1 , 2); i -=2;}\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int j = 0;\n for (int i = 0; i < s.size(); i++){\n if (s[i] == '*'){\n j--;\n } else {\n s[j++] = s[i];\n }\n }\n return s.substr(0, j);\n }\n};",
... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string ans=\"\";\n int cnt = 0;\n for (int i = s.size()-1; i>=0; --i) {\n if (s[i] == '*') {\n ++cnt;\n }\n else{\n if (cnt > 0) {\n --cnt;\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.size();\n int j = 0;\n for(int i = 0;i < n; i++){\n if(s[i] == '*'){\n j--;\n }else{\n s[j++] = s[i];\n }\n }\n return s.substr(0,j);\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n std::string removeStars(std::string s) \n {\n int i=0, j=0;\n\n for(i=0; i<s.size(); i++)\n {\n if(s[i]=='*')\n {\n j--;\n }\n else\n {\n s[j++] = s[i];\n }... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n \n string removeStars(string s) {\n int p = 0, q = 0, l = s.length();\n while(q < l)\n {\n if(s[q] >= 'a' && s[q] <= 'z')\n {\n s[p] = s[q];\n ++p;\n ++q;\n continue;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n const int n = s.size();\n char ans[n + 1];\n int j = 0;\n for(int i = 0; i < n; i++){\n\n while(s[i] == '*'){\n j--;\n i++;\n }\n ans[j++] = s[i];\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n \n const int n = s.size();\n char ans[n + 1];\n int j = 0;\n for(int i = 0; i < n; i++){\n\n while(s[i] == '*'){\n j--;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "#include <string_view>\n#include <algorithm>\nclass Solution {\npublic:\n string removeStars(string s) \n {\n /*\n const size_t string_length = s.size();\n size_t index = 0;\n while (index < string_length)\n {\n //const size_t index = s.find_first_of(\"*\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "#include <string_view>\n#include <algorithm>\nclass Solution {\npublic:\n string removeStars(string s) \n {\n\n std::string s2;\n\n const size_t string_length = s.size();\n s2.reserve(string_length * 0.5);\n int to_be_removed = 0;\n for (int i = string_length -1; i ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.length();\n\n string res = \"\";\n int ct = 0;\n for(int i = n-1; i >= 0; i--) {\n if(s[i] == '*') {\n ct++;\n }\n else {\n if(ct == 0) {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n=s.size();\n int strCnt=0;\n string ans;\n int i=s.length()-1;\n while(i>=0)\n {\n if(s[i]=='*')\n strCnt++;\n else if(strCnt>0)\n strCnt--;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int cntStar=0;\n string ans;\n for(int i=s.length()-1;i>=0;i--){\n if(s[i]=='*')\n cntStar++;\n else if(cntStar){\n cntStar--;\n }\n else ans+=s[i];\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string str = \"\";\n int n = s.size();\n int cnt = 0;\n for (int i = n - 1; i >= 0; i--) {\n if (s[i] == '*')\n cnt++;\n else {\n if (cnt) {\n c... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=s.length();\n string str=\"\";\n int star=0;\n for(int i=n-1;i>=0;i--){\n if(s[i]=='*') star++;\n else if(s[i]!='*' && star>0)... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int toDel = 0, counter = 0;\n vector<char> res;\n for(int i = s.size() - 1; i >= 0; i--)\n {\n while(i >= 0 && s[i] == '*')\n {\n while(i >= 0 && s[i] == '*')\n {\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 0 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int toDel = 0, counter = 0;\n vector<char> res;\n for(int i = s.size() - 1; i >= 0; i--)\n {\n while(i >= 0 && s[i] == '*')\n {\n while(i >= 0 && s[i] == '*')\n {\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s)\n {\n int i =0;\n vector<char> s_ = {};\n for(char c: s)\n {\n if(c=='*')\n {\n char c_ = s_.back();\n s_.pop_back();\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> stack_nostar;\n\n for (const auto& e: s){\n if (e == '*'){\n if (!stack_nostar.empty()){\n stack_nostar.pop();\n }\n } else {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.size();\n\n stack<char>st;\n\n for(int i = 0 ; i < n ; i++){\n\n if(s[i] == '*'){\n st.pop();\n }\n else{\n st.push(s[i]);\n }\n\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char>st;\n int n=s.size();\n string ans=\"\";\n for(int i=n-1;i>=0;i--){\n if(!st.empty() && (st.top()=='*' && s[i]!='*')){\n st.pop();\n }\n else{\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n stack<char>st;\n int n = s.length();\n int i = 0;\n if(n == 1)\n {\n return s;\n }\n for(i = 0 ; i < n-1 ; )\n {\n if(s[i] != '*' && s[i+1] != '*')\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n stack<char>st;\n int n = s.length();\n int i = 0;\n if(n == 1)\n {\n return s;\n }\n for(i = 0 ; i < n-1 ; )\n {\n if(s[i] != '*' && s[i+1] != '*')\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n stack<char>st;\n int n = s.length();\n int i = 0;\n if(n == 1)\n {\n return s;\n }\n for(i = 0 ; i < n-1 ; )\n {\n if(s[i] != '*' && s[i+1] != '*')\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n vector<char> st;\n for(int i=0;i<s.size();i++){\n if(s[i] == '*'){\n st.pop_back();\n }\n else{\n st.push_back(s[i]);\n }\n\n }\n string ans(... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 1 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char>st;\n for(int i =0 ; i<s.size() ; i++){\n if(s[i] != '*'){\n st.push(s[i]);\n }\n else{\n st.pop();\n }\n }\n string ans =\"\";\n\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 2 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n int n = s.size();\n string res;\n for(int i = 0;i<n;i++) {\n if (s[i] != '*') st.push(s[i]);\n else {\n if (!st.empty()) st.pop();\n }\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 2 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char>st;\n string ans = \"\";\n for(char c : s){\n if(c=='*'){\n st.pop();\n }\n else st.push(c);\n }\n\n while(!st.empty()){\n ans += st.top()... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n std::ios_base::sync_with_stdio(false); \n std::cin.tie(NULL);\n std::cout.tie(NULL);\n\n stack<char>st;\n for(int i=0;i<s.length();i++)\n {\n if(s[i] != '*')\n {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n std::ios_base::sync_with_stdio(false); \n std::cin.tie(NULL);\n // std::cout.tie(NULL);\n\n stack<char>st;\n for(int i=0;i<s.length();i++)\n {\n if(s[i] != '*')\n {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n ios::sync_with_stdio(false);cin.tie(nullptr);\n stack<char>st;\n for(int i=0; i<s.size();i++){\n if(isalpha(s[i]))st.push(s[i]);\n if(s[i]=='*')st.pop();\n }\n string ans=\"\";\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string ans = \"\";\n vector<char>vec;\n for(int i = 0; i<s.size();i++){\n if(i>0 && s[i]=='*'){\n vec.pop_back();\n }\n else if(s[i]!='*'){\n vec.push_back(s[i... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n vector<char> stack;\n int n=s.size();\n for(int i=0;i<n;i++){\n if(s[i]=='*'){\n stack.pop_back();\n }\n else{\n stack.push_back(s[i]);\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n for(int i=0; i<s.length(); i++){\n if(s[i] != '*'){\n st.push(s[i]);\n }\n else{\n if(!st.empty())\n st.pop();\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n \n string res = \"\";\n stack<char> k;\n stack<char> k1;\n\n for(auto i:s){\n if(i == '*'){\n k.pop();\n }\n else{\n k.push(i);\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string rs = s;\n int n = 0;\n for(auto i: s){\n if(i == '*') n--;\n else {\n rs[n++] = i;\n }\n }\n return rs.substr(0, n);\n }\n};",
"memory": "29386"
} |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n //vector <char> myvector;\n int n = s.size();\n char *temp = (char*) calloc(n+1, sizeof(char));\n int start = 0;\n for(int i = 0; i< n; i++){\n if(s[i] != '*') temp[start++] = s[i];\n el... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> stack_nostar;\n std::string string_nostar;\n\n for (const auto& e: s){\n if (e == '*'){\n if (!stack_nostar.empty()){\n stack_nostar.pop();\n }\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> stack_nostar;\n std::string string_nostar;\n\n for (const auto& e: s){\n if (e == '*'){\n if (!stack_nostar.empty()){\n stack_nostar.pop();\n }\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n string res = \"\";\n\n for(int i=0; i<s.length(); i++){\n st.push(s[i]);\n\n if(st.top() == '*'){\n st.pop();\n if(!st.empty()){\n st... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> stck;\n for (auto item : s) {\n stck.push(item);\n if (stck.top() == '*') {\n stck.pop();\n if (stck.size() > 0) stck.pop();\n }\n }\n\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) \n {\n // add each character to a stack\n // if we get a star, pop twice\n // resulting stack is our string\n stack<char> stack;\n string result = \"\";\n for (int i = 0; i < s.length(); i++)\n {... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char>st;\n for(auto x:s){\n if(x!='*')st.push(x);\n else st.pop();\n }\n string w=\"\",h=\"\";\n while(st.size()>0){\n\n char ch=st.top();\n st.pop();\n w+=ch;\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n vector<char> v(s.size(), ' ');\n\n int ptr = 0;\n for(int i=0; i<s.size(); i++){\n if(s[i]=='*'){\n ptr--;\n }else{\n v[ptr] = s[i];\n ptr++;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n // stack<char>stk;\n // for (auto c : s) {\n // if (c == '*') {\n // stk.pop();\n // } else {\n // stk.push(c);\n // }\n // }\n // string ans;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.length();\n string ans = \"\";\n vector<char> result(n);\n int j = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == '*') {\n j--;\n } else {\n res... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n \n string removeStars(string s) {\n stack<char>st;\n for(auto i:s){\n st.push(i);\n if(st.top()=='*'){\n st.pop();\n if(!st.empty()){\n st.pop();\n }\n }\n }\n stack<char>temp... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n string r;\n for(char a:s)\n {\n if(a!='*')\n {\n st.push(a);\n }\n else\n {\n if(st.empty())\n {\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n for(int i=0;i<s.length();i++){\n st.push(s[i]);\n }\n s=\"\";\n int cnt=0;\n while(!st.empty()){\n if(st.top()!='*'){\n s.push_back(st.top());\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\n if(count(s.begin(), s.end(),'*') == 0)\n return s;\n stack<char> st;\n string temp;\n int count = 0;\n for(int i =0; i<s.size(); i++)\n st.push(s[i]);\n while(!st.empty())\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\n if(count(s.begin(), s.end(),'*') == 0)\n return s;\n stack<char> st;\n string temp;\n int count = 0;\n for(int i =0; i<s.size(); i++)\n st.push(s[i]);\n while(!st.empty())\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\n if(count(s.begin(), s.end(),'*') == 0)\n return s;\n stack<char> st;\n string temp;\n int count = 0;\n for(int i =0; i<s.size(); i++)\n st.push(s[i]);\n while(!st.empty())\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\n if(count(s.begin(), s.end(),'*') == 0)\n return s;\n stack<char> st;\n string temp;\n int count = 0;\n for(int i =0; i<s.size(); i++)\n st.push(s[i]);\n while(!st.empty())\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n\n if(count(s.begin(), s.end(),'*') == 0)\n return s;\n stack<char> st;\n string temp;\n int count = 0;\n for(int i =0; i<s.size(); i++)\n st.push(s[i]);\n while(!st.empty())\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string printstack(stack<char> s){\n\n stack<char> temp;\n\n while(s.empty() == false){\n int x = s.top();\n s.pop();\n temp.push(x);\n\n }\n string ss;\n while(temp.empty() == fal... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string res=\"\";\n stack<char>st;\n for(char c:s)\n st.push(c);\n int count=0;\n while(!st.empty())\n {\n if(st.top()=='*')\n {\n count++;\n s... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n string ans = \"\";\n\n stack<char> myStack;\n for (auto c : s) {\n myStack.push(c);\n }\n\n int numRemovals = 0;\n while (!myStack.empty()) {\n if (myStack.top() == '*') {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.size();\n stack<char> stk;\n for(int i =0;i<n;i++) stk.push(s[i]);\n int cnt=0;\n string result;\n char tmp;\n for(int i = 0;i<n;i++){\n tmp = stk.top();\n stk.po... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n ios::sync_with_stdio(0);\n stack<char>st;\n for(auto it : s)st.push(it);\n string str = \"\";\n while(!st.empty()){\n int cnt = 0;\n if(st.top() == '*'){\n while(st.top() ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n ios::sync_with_stdio(0);\n stack<char>st;\n for(auto it : s)st.push(it);\n string str = \"\";\n while(!st.empty()){\n int cnt = 0;\n if(st.top() == '*'){\n while(st.top() ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n class stack{\n public:\n int size;\n int top;\n int * arr;\n };\n void push(stack* p,char val){\n p->top++;\n p->arr[p->top] = val;\n }\n void pop(stack*p){\n p->top--;\n }\n string removeStars(string s) {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st, st2;\n for (auto c : s)\n st.push(c);\n int times = 0;\n bool check = false;\n string ans = \"\";\n while (!st.empty()) {\n if (st.top() == '*') {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n stack<char> ans_st;\n string ans;\n\n for(int i = 0; i < s.length(); i++)\n {\n st.push(s[i]);\n }\n\n while(!st.empty())\n {\n int count = 1;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> stuff;\n for (int i = 0; i < s.size(); i++) {\n stuff.push(s[i]);\n }\n string out;\n int deleter = 0;\n while (stuff.size() > 0) {\n while (stuff.top() == '*') {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "//using stack\nclass Solution {\npublic:\n string removeStars(string s) {\n int size = s.length();\n //push all characters to the stack\n stack<char> mystack;\n stack<char> solution;\n for(int i=0; i<size; i++) mystack.push(s[i]);\n\n int starcount = 0;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) { \n //return bf(s); \n return optimal(s);\n }\n\n std::string optimal(std::string s) {\n std::stack<char> stack;\n for (auto ch: s) {\n if (stack.empty()) {\n stack.push(ch);... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s)\n {\n int N = s.size();\n int pendingOpStarCount = 0;\n vector<int> remIndices;\n for (int i = N - 1; i >= 0; i--)\n {\n if (s[i] == '*')\n {\n pendingOpStarCount++;\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char>st;\n int a=0;\n for(int i=0;i<s.length();i++){\n st.push(s[i]);\n }\n string ans=\"\";\n while(!st.empty()){\n if(st.top()!='*'){\n if(a==0){\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "\nclass Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n for(char c:s)\n {\n st.push(c);\n }\n \n string res;\n while(!st.empty())\n {\n \n int cnt = 0;\n while(st.top()=='*')\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "#include <string>\n\nclass Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n string out = \"\";\n int star = 0;\n for (char c : s) {\n st.push(c);\n }\n while (!st.empty()) {\n if (st.top() == '*') {\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\nstack<char> toStack(string x) {\n\tint size = (int)x.length();\n\tstack<char> answer;\n\tfor (int i = 0; i < size; i++) {\n\t\tif (x[i] == '*' && !answer.empty()) {\n\t\t\tanswer.pop();\n\t\t}if (x[i] == '*') {\n\t\t\tcontinue;\n\t\t}\n\t\telse {\n\t\t\tanswer.push(x[i]);\n\t\t}\... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> st;\n stack<char> st2;\n string ans = \"\";\n reverse(s.begin(),s.end());\n for(char c : s){\n st.push(c);\n }\n while(!st.empty()){\n if(st.top()!='*'){\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<char> fuck;\n\n for(auto &cur : s) fuck.push(cur);\n\n string result = \"\";\n\n while(!fuck.empty()){\n char cur = fuck.top();\n fuck.pop();\n int starCount = 0;\n\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n s += '#';\n stack<char> sc;\n for (int i = 0; i < s.length(); i++){\n if (s[i] == '*'){\n if (!sc.empty()) sc.pop();\n }\n else sc.push(s[i]);\n }\n stack <char> ans;\n while(!sc.empty()){\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> string_star;\n std::string string_nostar, string_reverse;\n int star_num = 0;\n\n for (const auto& e: s){\n string_star.emplace(e);\n }\n\n while (!string_star.empty()){\n\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> string_star;\n std::string string_nostar, string_reverse;\n int star_num = 0;\n\n for (const auto& e: s){\n string_star.emplace(e);\n }\n\n while (!string_star.empty()){\n\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n std::stack<char> string_star;\n std::string string_nostar, string_reverse;\n int star_num = 0;\n\n for (const auto& e: s){\n string_star.emplace(e);\n }\n\n while (!string_star.empty()){\n\n... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<int> st;\n \n for ( int i=0; i<s.length(); i++ )\n {\n if ( s[i] != '*')\n st.push( s[i] );\n else if ( !st.empty() )\n st.pop();\n }\n \n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n \n stack<int> stackLetters;\n for(auto c : s)\n {\n if(c!='*')\n {\n stackLetters.push(c);\n }\n else\n {\n if(!stackLetters.empty... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n vector<int> stack;\n for(int i = 0; i < s.size(); i++) {\n if(s[i] == '*') {\n if(stack.size() != 0) {\n s[stack.back()] = '#';\n s[i] = '#';\n st... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<int> st;\n for(int i = 0; i < s.size(); i++) {\n if(!st.empty() && s[i] == '*')\n st.pop();\n if(s[i] != '*') {\n st.push(s[i]);\n }\n }\n string ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<int>st;\n int n = s.size();\n int i = 0;\n while(i<n){\n if(s[i] == '*'){\n st.pop();\n }\n else{\n st.push(s[i]);\n }\n i++... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<int>st;\n\n for(int i = 0; i<s.length(); i++){\n if(s[i] == '*'){\n if(!st.empty()){\n st.pop();\n }\n }else{\n st.push(s[i]);\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n int n = s.size();\n stack<int> st;\n string ans = \"\";\n for(int i = 0;i < n; i++){\n if(s[i] == '*'){\n st.pop();\n }else{\n st.push(s[i]);\n }\n ... |
2,470 | <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
<p>In one operation, you can:</p>
<ul>
<li>Choose a star in <code>s</code>.</li>
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
</ul>
<p>Return <em>th... | 3 | {
"code": "class Solution {\npublic:\n string removeStars(string s) {\n stack<int>st;\n int n = s.size();\n int i = 0;\n while(i<n){\n if(s[i] == '*'){\n st.pop();\n }\n else{\n st.push(s[i]);\n }\n i++... |
2,471 | <p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>'M'</code>, <code>'P'</code> and <code>'G'... | 0 | {
"code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int gi=-1,pi=-1,mi=-1,ans=0,n = garbage.size(); \n //gi pi mi all store lastindex of glass plastic metal respectively\n for(int i=0;i<n;i++){\n for(auto &ch:garbage[i]){\n ... |
2,471 | <p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>'M'</code>, <code>'P'</code> and <code>'G'... | 0 | {
"code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int c = 0, g = 0, p = 0, m = 0, d = 0;\n for(int i = 0; i < garbage.size(); i++)\n {\... |
2,471 | <p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>'M'</code>, <code>'P'</code> and <code>'G'... | 0 | {
"code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int c = 0, g = 0, p = 0, m = 0, d = 0;\n for(int i = 0; i < garbage.size(); i++)\n {\... |
2,471 | <p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>'M'</code>, <code>'P'</code> and <code>'G'... | 0 | {
"code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);\n int ans=0;\n int n=garbage.size();\n int i=0;\n int dism=0,disg=0,disp=0;\n for(auto it:garbage... |
2,471 | <p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>'M'</code>, <code>'P'</code> and <code>'G'... | 0 | {
"code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int Ppick=0;\n int Gpick=0;\n int Mpick=0;\n\n int travelP=0;\n int travelG=0... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.