id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
0
{ "code": "class Solution {\npublic:\n int nextNum(int n){\n int totalSum = 0;\n while(n != 0){\n int d = n % 10;\n totalSum += d*d;\n n = n / 10;\n }\n return totalSum;\n }\n bool isHappy(int n) {\n int slow = n;\n int fast = nextNum...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
0
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n if(n == 1 || n == 7){\n return true;\n }\n if(n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 8 || n == 9){\n return false;\n }\n int ans = 0;\n int rm = n;\n while(rm > 0){\...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
0
{ "code": "class Solution {\npublic:\n bool isHappy(int n)\n {\n int slow = n;\n int fast = n;\n\n while (fast != 1)\n {\n slow = SumDigitsSquared(slow);\n fast = SumDigitsSquared(fast);\n if (fast == 1)\n {\n return true;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
0
{ "code": "// class Solution {\n// public:\n// bool isHappy(int n) {\n// int digit=0;\n// int t;\n// while(n>9){\n// while(n>0){\n// t=n%10;\n// digit=digit*digit+t*t;\n// n=n/10;\n// }\n// n=digit;\n// }\n// ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
0
{ "code": "// class Solution {\n// public:\n// bool isHappy(int n) {\n// int digit=0;\n// int t;\n// while(n>9){\n// while(n>0){\n// t=n%10;\n// digit=digit*digit+t*t;\n// n=n/10;\n// }\n// n=digit;\n// }\n// ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\nprivate:\n int nextNumber(int n){\n int newNumber = 0;\n while(n!=0){\n int num = n%10;\n newNumber += num*num;\n n = n/10;\n }\n return newNumber;\n }\npublic:\n bool isHappy(int n) {\n int slowPointer = n;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n)\n {\n int slow = n;\n int fast = n;\n\n while (fast != 1)\n {\n slow = SumDigitsSquared(slow);\n fast = SumDigitsSquared(fast);\n if (fast == 1)\n {\n return true;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n int digit = 0;\n vector<int> arr;\n\n while(n!=1){\n n = getnumber(n);\n int cnt = count(arr.begin(),arr.end(),n);\n if(cnt){\n return false;\n }\n arr.emplace_b...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n\nint giveNo(int n){\n int sum=0;\n while(n!=0){\n int digit=n%10;\n sum+=digit*digit;\n n/=10;\n }\n return sum;\n}\n\n bool isHappy(int n) {\n if(n==1){\n return true;\n }\n // if(n<10 && n!=1){\n // ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\nprivate:\nint sum(int n){\n int totalsum=0;\n while(n>0){\n int digit = n%10;\n totalsum+=digit*digit;\n n = n/10;\n }\n return totalsum;\n}\npublic:\n bool isHappy(int n) {\n set<int>s;\n while(n!=1&&s.find(n)==s.end()){\n s.in...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n int i = 0;\n vector<int> digits;\n vector<int> loop_check;\n do{\n while(n > 0){\n int digit = pow(n % 10, 2);\n digits.push_back(digit);\n n /= 10;\n }\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n set<int> s;\n while(1){\n int sum=0;\n while(n){\n int r=n%10;\n sum+=pow(r,2);\n n=n/10;\n }\n if(sum==1){\n return true;\n }\...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n set<int> st;\n int val;\n int temp;\n\n while(true){\n val = 0;\n while(n){\n temp = n%10;\n val+= (temp*temp);\n n= n/10;\n }\n if(val...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n int tmp = n;\n vector<int> digits;\n set<int> seen;\n while(tmp != 1) {\n // printf(\"%d\\n\", tmp);\n if (seen.find(tmp) != seen.end()) {\n return false;\n }\n seen...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n set<long long> st;\n while (n != 1) {\n long long temp = 0;\n while (n) {\n int rem = n % 10;\n temp += rem * rem;\n n /= 10;\n }\n if (st.find(temp) != st.end())\n retu...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\nprivate:\n int nextNumber(int n){\n int newNumber = 0;\n while(n!=0){\n int num = n%10;\n newNumber += num*num;\n n = n/10;\n }\n return newNumber;\n }\npublic:\n bool isHappy(int n) {\n unordered_set<int> set;\n...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
1
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_set<int> visit;\n \n while (visit.find(n) == visit.end()) {\n visit.insert(n);\n n = getNextNumber(n);\n if (n == 1) {\n return true;\n }\n }\n \n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
2
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_set<int> usedIntegers; // To keep track of numbers we have seen\n\n\n while(true){\n int sum=0;\n int temp=n;\n// Calculate the sum of squares of digits\n while(temp!=0){\n int dig...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
2
{ "code": "class Solution {\npublic:\n int sumOfSquares(int n) {\n int sum = 0;\n while (n > 0) {\n int digit = n % 10;\n sum += digit * digit;\n n /= 10;\n }\n return sum;\n}\n\n// Function to determine if a number is happy\nbool isHappy(int n) {\n unordered_set<int> seen; // T...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
2
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_set<int>st;\n \n while(st.find(n) == st.end()){\n st.insert(n);\n int sum = 0;\n while(n){\n int rem = n % 10;\n sum = sum + (rem * rem);\n n =...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_map<int, int> mp;\n while(n != 1){\n int sum = 0;\n while(n != 0){\n int r = n%10;\n sum = sum + r*r;\n n = n/10;\n }\n n = sum;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_map<int, int> mp;\n while(n != 1){\n int sum = 0;\n while(n != 0){\n int r = n%10;\n sum = sum + r*r;\n n = n/10;\n }\n n = sum;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "#include <ranges>\n\nclass Solution {\npublic:\n bool isHappy(int n) {\n std::unordered_set<int> encountered;\n\n auto get_digits = [] (int n) {\n std::vector<int> result;\n\n while (n != 0) {\n result.push_back(n % 10);\n n /= 10;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n unordered_map<int,int> tmp;\n \n while(n != 1)\n {\n if(tmp[n] == 0)\n tmp[n]++;\n else\n return false;\n \n int sum = 0;\n while(n != 0)\n...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n int sum = sumSqDigits(n);\n map<int,bool>prevValues;\n prevValues[sum]=true;\n while(sum != 1) {\n sum = sumSqDigits(sum);\n if(prevValues.find(sum) != prevValues.end()) {\n break;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n // record numbers seen\n unordered_map<int, int> record;\n while(1) {\n // if the number has been seen \n // a cycle is complete\n if(record[n] == 1) break;\n record[n] = 1;\n\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "\nclass Solution {\npublic:\n bool isHappy(int n) {\n return helper(n);\n }\n\nprivate:\n std::unordered_set<int> seen; // Store sums we've seen\n\n bool helper(int n) {\n int sumsq = 0;\n while (n > 0) {\n sumsq += pow(n % 10, 2); // Sum of squares of digits\n...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\nprivate:\n unordered_set<int> mySet;\npublic:\n bool detectCycle(int n){\n // cout<< \"Size of set is \"<< mySet.size()<< endl;\n if(mySet.count(n)) return true;\n mySet.insert(n);\n return false;\n\n }\n bool isHappy(int n) { \n int s...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "\n\nclass Solution {\nprivate:\n int calculateSumOfSquares(int n) { \n int sum = 0;\n while (n > 0) {\n int digit = n % 10;\n sum += digit * digit;\n n /= 10;\n }\n return sum;\n }\n\n bool isHappyUtil(int n, unordered_set<int>& seen) {\...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n \n string s=to_string(n);\n while(s.size()>1){\n int sum=0;\n for(int i=0;i<s.size();i++){\n int a=s[i]-'0';\n sum+=a*a;\n }\n s=to_string(sum);\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n unordered_set<int>m;\n bool isHappy(int n) {\n cout<<n<<endl;\n if(n==1)\n return true;\n if(m.find(n)!=m.end())\n return false;\n\n m.insert(n);\n int sum=0;\n while(n>0){\n int dig=n%10;\n ...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n bool isHappy(int n) {\n bool b = true;\n int curr = n;\n int next = 0;\n\n map<int,int> m = {};\n\n while (b)\n {\n int digit = curr%10;\n next += digit*digit;\n curr /= 10;\n //print digit\...
202
<p>Write an algorithm to determine if a number <code>n</code> is happy.</p> <p>A <strong>happy number</strong> is a number defined by the following process:</p> <ul> <li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li> <li>Repeat the process until the number equal...
3
{ "code": "class Solution {\npublic:\n map<int,int> mp;\n bool isHappy(int n) {\n\n if(n==1) return true;\n if(n<=0) return false;\n int sum=0;\n while(n>0)\n {\n int dig=n%10;\n sum+=dig*dig;\n n/=10;\n } \n if(mp.find(sum)==mp.e...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static const int __ = []()...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
1
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
1
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n class Solution {\npublic:\...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
3
{ "code": "class Solution {\npublic:\n ListNode* removeElements(ListNode* head, int val) {\n if(head == nullptr){\n return nullptr;\n }\n\n head->next = removeElements(head->next, val);\n\n if(head->val == val){\n return head->next;\n } else{\n r...
203
<p>Given the <code>head</code> of a linked list and an integer <code>val</code>, remove all the nodes of the linked list that has <code>Node.val == val</code>, and return <em>the new head</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
0
{ "code": "class Solution {\npublic:\n void DFS(int ind, int l, int r, const string &s, vector<string> &ret, string &path) {\n // l is the number of '('s and r is the number of ')'s in path\n\tif(r>l) return;\n\t\n\tif(ind==s.size()) {\n\t // if !ret.empty(), we find one longest valid string\n\t\tif(l==r && ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
0
{ "code": "class Solution {\npublic:\n void DFS(int ind, int l, int r, const string& s, vector<string>& ret,\n string& path) {\n if (r > l)\n return;\n\n if (ind == s.size()) {\n if (l == r && (ret.empty() || path.size() == ret[0].size()))\n ret.push_b...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
1
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n int n = s.size();\n if(!n)\n return {};\n vector<string>ret;\n int l = 0, r = 0;\n for(const auto&c:s){\n if(c == '(')\n l++;\n else if(c =...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
1
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n // f[i][j] = list of results for s[i..j]\n \n int n = s.length();\n \n vector<vector<int>> f(n, vector<int>(n, 0));\n vector<vector<unordered_set<string>>> g(n, vector<unordered_set<string>>(n));\n \n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\n bool isStringValidParentheses(string s)\n {\n if(s.length() == 0) return true;\n \n int count = 0;\n for(char ch:s)\n {\n if(ch == '(')\n count++;\n else if(ch == ')')\n count--;\n\n if(count...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\nset<string> globalSet;\nstring s;\nstring cur;\nint balance=0;\n\nvoid dfs(int i)\n{\n if(balance<0) return;\n // cout<<cur<<endl;\n\n if(i>=s.size())\n {\n // cout<<i<<endl;\n // cout<<balance<<\" \"<<cur<<\" \"<<globalSet.size()<<\" \"<<*globalSet.begi...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\n int max_string_size;\n set<string> result;\n vector <int> closed_p;\n \n vector<string> removeInvalidParentheses(string s) {\n max_string_size = 0;\n \n int open = 0;\n int closed = 0;\n int char_count = 0;\n \n for(...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\nprivate:\n int getRemoval(string &s){\n\n stack<char>st;\n\n for(char& ch: s){\n if(ch == '('){\n st.push(ch);\n }\n else if(ch == ')'){\n if(st.empty() || st.top() == ')'){\n st.push(ch);\n }\n else ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\n std::vector<std::string> removeInvalidParentheses(const std::string& s) {\n std::vector<std::string> result;\n std::unordered_set<std::string> visited;\n std::queue<std::string> queue;\n bool found = false;\n\n queue.emplace(s);\n vis...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\n int getMinInvalid(string s)\n {\n stack<char> st;\n int i=0;\n while(i<s.size())\n {\n if(s[i] == '(')\n {\n st.push(s[i]);\n }\n else if(s[i] == ')')\n {\n if(...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
2
{ "code": "class Solution {\npublic:\n vector<string> res;\n unordered_map<string,int> m;\n vector<string> removeInvalidParentheses(string s) {\n //try all possible ways --> Recursion\n //remove each char and check inValid chars in substring\n //\"()())()\" --> check inValid chars in [\"...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n \n vector<string>ans;\n unordered_map<string,int>mp;\n int getvalid(string s){\n stack<char>st;\n int i=0;\n while(i<s.size()){\n if(s[i] == '(')st.push('(');\n else if(s[i] == ')'){\n if(st.size() && st.top() ==...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n // Очередь для хранения планируемых состояний к обходу\n // строка - вершина графа\n queue<string> q{{s}};\n unordered_map<string, int> dist{{s, 0}};\n int minResLevel = 1e9;\n vec...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void f(int i,int count,string temp,string &str,int &k,vector<string>&ans,set<pair<int,string>>&s,int&n){\n if(s.count({i,temp}))return;\n s.insert({i,temp});\n if(i>=n){\n cout<<temp<<\" \"<<count<<endl;\n if(count==0 && (n-temp.size...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void f(int i,int count,string temp,string &str,int &k,vector<string>&ans,set<pair<int,string>>&s,int&n){\n if(s.count({i,temp}))return;\n s.insert({i,temp});\n if(i>=n){\n if(count==0 && (n-temp.size())==k){\n ans.push_back(temp)...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n bool isValid(string s) {\n stack<char> st;\n\n for(char c: s) {\n if(c == '(') {\n st.push(c);\n }\n else if (c == ')') {\n if(st.empty())\n return false;\n st.pop(...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n string str;\n\n bool isValid(int removedIndices){\n int leftCtr = 0;\n for (int i = 0; i < str.length(); ++i){\n if ((1 << i) & removedIndices){\n continue;\n }\n if (str[i] == '('){\n ++leftCtr;...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int removalCount(string s)\n {\n int ans = 0;\n int openCount = 0;\n for(int i = 0; i<s.size(); i++)\n {\n if(s[i] == '(')\n openCount++;\n else if(s[i] ==')')\n {\n if(openCount>0)\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int getMinimumRemovals(string &str){\n\n stack<char> s;\n\n for(int i=0;i<str.size();i++){\n if(str[i]=='('){\n s.push(str[i]);\n }\n else if(str[i]==')'){\n if(s.empty() || (!s.empty() && s.top()=='...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string>ans;\n\n void call(string s, int pos, string output , int open , int close)\n {\n if(abs(open-close)>s.size()-pos)\n return ;\n if(pos==s.size())\n {\n if(open!=close || output.size()==0)\n return;\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\nbool ck(string s){\n stack<char>st;\n for(int i=0;i<s.size();i++){\n if(s[i]=='('){\n st.push('(');\n }\n else if(s[i]==')'){\n if(st.empty())return false;\n st.pop();\n }\n }\n if(st.empty())return true;\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n unordered_set<string> result;\n int left_removed = 0;\n int right_removed = 0;\n for(auto c : s) {\n if(c == '(') {\n ++left_removed;\n }\n if(c =...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n bool CheckValid(string &str)\n {\n stack<char> st;\n int i = 0, n = str.size();\n while(i < n)\n {\n if(str[i] == '(')\n {\n st.push(str[i]);\n }\n else if(str[i] == ')')\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n bool CheckValid(string &str)\n {\n stack<char> st;\n int i = 0, n = str.size();\n while(i < n)\n {\n if(str[i] == '(')\n {\n st.push(str[i]);\n }\n else if(str[i] == ')')\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "// class Solution {\n// public:\n// int minDeletionsToBalanceString(string s){\n// stack<char> st;\n// for(auto c: s){\n// if (c!='(' and c!=')') continue; // s can contain lowercase characters as well\n// if(c=='(')\n// st.push('(');\n// ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int minDeletionsToBalanceString(string s){\n stack<char> st;\n for(auto c: s){\n if (c!='(' and c!=')') continue; // s can contain lowercase characters as well\n if(c=='(')\n st.push('(');\n else{\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int checkforbalancedParanthesis(string str){\n stack<char>st;\n for(int i=0;i<str.size();i++){\n if(str[i]=='('){\n st.push(str[i]);\n }\n else if(str[i]==')'){\n if(st.size()!=0 && st.top()=='(') st...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector <string> ans;\n int findrem(string s)\n {\n int n = s.size();\n stack <int> st;\n for(auto it : s)\n {\n if(it=='(') st.push('(');\n else if(it==')') \n {\n if(!st.empty() && st.top()=='(') st.pop(...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n /* get relative count of '(' and ')' */\n int getParValue(string s)\n {\n int _count = 0;\n for (int i=0; i<s.size(); i++) {\n if (s[i] == '(') _count++;\n else if (s[i] == ')' && _count-- == 0) return _count;\n }\n retu...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\n bool isValid(string s) {\n int balance = 0;\n for (char c : s) {\n if (c == '(') balance++;\n else if (c == ')') {\n balance--;\n if (balance < 0) return false; // Early exit on invalidity\n }\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void backtrack(unordered_set<string>& ans, unordered_map<string, int>& mp2, string& s, string& o, int idx) {\n if (s.length() == idx)\n return;\n\n o.push_back(s[idx]);\n \n if (mp2[o] == 0) {\n solve(ans, o);\n backtrack(ans, mp2, s, o, idx +...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string>ans;\n\n void call(string s, int pos, string output , int open , int close)\n {\n if(pos==s.size())\n {\n if(open!=close || output.size()==0) //output.size()==0 not needed if we use set\n return;\n if(ans....
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string>ans;\n\n void call(string s, int pos, string output , int open , int close)\n {\n if(pos==s.size())\n {\n if(open!=close || output.size()==0) //output.size()==0 not needed if we use set\n return;\n if(ans....
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<int> get_count(const std::string& s) {\n int left = 0;\n int right = 0;\n int open = 0;\n\n for (char c : s) {\n if (c == '(') {\n ++open;\n } else if (c == ')') {\n if (open == 0) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n bool isValid(const string& s)\n {\n stack <char> sk;\n int slen = s.size();\n for (auto c : s)\n {\n if (c == ')')\n {\n if (sk.empty())\n return false;\n else\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n bool isValid(const string& s)\n {\n stack <char> sk;\n int slen = s.size();\n for (auto c : s)\n {\n if (c == ')')\n {\n if (sk.empty())\n return false;\n else\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n bool isValid(const string& s)\n {\n stack <char> sk;\n int slen = s.size();\n for (auto c : s)\n {\n if (c == ')')\n {\n if (sk.empty())\n return false;\n else\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n map<string,bool> dp;\n bool isValid(string s){\n if(!s.size()) return false;\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 if(s[i]=...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n bool isValid(string x) {\n stack<char> st;\n for (char c : x) {\n if (c == '(') {\n st.push(c);\n } else if (c == ')') {\n if (!st.empty() && st.top() == '(') {\n st.pop();\n }...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int checkRBS(string& s) {\n int n = s.size(), cnt=0;\n vector<int> st, inval;\n for(int i=0; i<n; i++) {\n if(s[i]=='(') {\n st.push_back(i);\n }\n else if(s[i]==')'){\n if(!st.empty()) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int checkRBS(string& s) {\n int n = s.size(), cnt=0;\n vector<int> st, inval;\n for(int i=0; i<n; i++) {\n if(s[i]=='(') {\n st.push_back(i);\n }\n else if(s[i]==')'){\n if(!st.empty()) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n string remove_open(string_view s, int count)\n {\n vector<const char*> to_remove;\n string result;\n\n cout << \"TO FIX OPEN: \" << s << \",\" << count << endl; \n\n for (auto start = rbegin(s); start != rend(s) && count; --count, ++start)\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n string remove_open(string_view s, int count)\n {\n vector<const char*> to_remove;\n string result;\n\n cout << \"TO FIX OPEN: \" << s << \",\" << count << endl; \n\n for (auto start = rbegin(s); start != rend(s) && count; --count, ++start)\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n string remove_open(string_view s, int count)\n {\n vector<const char*> to_remove;\n string result;\n\n cout << \"TO FIX OPEN: \" << s << \",\" << count << endl; \n\n for (auto start = rbegin(s); start != rend(s) && count; --count, ++start)\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n int countParenthesesToRemove(string& s) {\n int balance = 0, parenthesesToRemove = 0;\n for (char c : s) {\n if (c == '(') {\n balance++;\n }\n else if (c == ')') {\n if (balance == 0) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n int cnt = numberOfInvalidParam(s);\n vector<string> ans;\n set<string> st;\n map<string, int> map;\n solve(s, st, cnt, map);\n for (auto it : st) \n ans.push_back(it);\n...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n bool isValid(string &s){\n int open = 0;\n for(int i=0; i<s.length(); i++){\n if(s[i] == '(') open++;\n else if(s[i] == ')'){\n open--;\n if(open < 0) return false;\n }\n }\n return ope...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n set<string> st;\n void getCount(vector<int> &vis,string &s,int ind,int &n,vector<string> &ans,int count)\n {\n if(count<0)\n {\n return ;\n }\n if(ind<0 || count==0)\n {\n int sm=0;\n string temp=\"\";\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> st;\n void getCount(vector<int> &vis,string &s,int ind,int &n,vector<string> &ans,int count)\n {\n if(count<0)\n {\n return ;\n }\n if(ind<0 || count==0)\n {\n int sm=0;\n string t...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\nprivate:\n\n unordered_map <int, unordered_set <string> > result;\n int minCount = INT_MAX;\n bool isValid(string &input)\n {\n int open = 0;\n for(int i = 0; i < input.size(); i++)\n {\n if(input[i] == '(')\n open++;\n ...