id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n\n int score = 0;\n\n string score_x( string s, int x ){\n\n string str = \"\";\n stack<char> st;\n\n for( int i=s.size()-1; i>=0; i-- ){\n\n if( !st.empty() && st.top() == 'b' && s[i] == 'a' ){ score += x; st.pop(); continue; }\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\nstring solve(string s,string str){\n stack<char>st;\n for(int i=0;i<s.size();i++){\n if(s[i]==str[1]&&!st.empty()&&st.top()==str[0])\n st.pop();\n else\n st.push(s[i]);\n }\n string a=\"\";\n while(!st.empty()){\n a+=st.top();\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\n string tryBA(string s, int& ans, int val){\n int cnt=0;\n stack<char>st;\n\n for(int i=0;i<s.length();i++)\n {\n if(s[i]=='a')\n {\n if(!st.empty() && st.top()=='b')\n {\n cnt++;\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\nstring removeBA(string s, int &count)\n{\n stack<char> stacky;\n for (auto x : s)\n {\n if (x == 'a' && !stacky.empty() && stacky.top() == 'b')\n {\n count++;\n stacky.pop();\n }\n else\n {\n stacky.push...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\n string remove_substring(string s,string pair,int point,int &score){\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n stack<char> st;\n for(int i=0;i<s.length();i++){\n if(s[i]==pair[1]&&!st.empty()&&st.top()==pair[0]){\n...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n stack<char>st;\n int ans=0;\n for(int i=0;i<s.length();i++)\n {\n if(!st.empty() && st.top()=='a' && s[i]=='b')\n {\n ans+=x;\n st.pop();\n }\n el...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n stack<char> stk;\n string r;\n int points = 0;\n for (char ch : s) {\n stk.push(ch);\n if (stk.size() > 1) {\n char head = stk.top(); stk.pop();\n char ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n vector<bool> del(s.size(), 0);\n if (x > y) return delAB(s, x, del) + delBA(s, y, del);\n return delBA(s, y, del) + delAB(s, x, del);\n }\n int delAB(string& s, int& x, vector<bool>& del){\n int poi...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n vector<bool> del(s.size(), 0);\n if (x > y) return delAB(s, x, del) + delBA(s, y, del);\n return delBA(s, y, del) + delAB(s, x, del);\n }\n int delAB(string& s, int& x, vector<bool>& del){\n int poi...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\nprivate:\n int process(string &s, int cost, string &target) {\n stack<int> st;\n int maxi = 0;\n for (int i = 0; i < s.size(); ++i) {\n if (!st.empty() && st.top() == target[0] && s[i] == target[1]) {\n st.pop();\n maxi += c...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n pair<int,string> solve(string s,string target,int c){\n stack<char> st;\n int ans=0;\n for(auto it:s){\n if(!st.empty() && st.top()==target[0] && it==target[1]){\n ans+=c;\n st.pop();\n }\n el...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n pair<int,string> solve(string s,string target,int c){\n stack<char> st;\n int ans=0;\n for(auto it:s){\n if(!st.empty() && st.top()==target[0] && it==target[1]){\n ans+=c;\n st.pop();\n }\n el...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n pair<int,string> solve(string s,string target,int c){\n stack<char> st;\n int ans=0;\n for(auto it:s){\n if(!st.empty() && st.top()==target[0] && it==target[1]){\n ans+=c;\n st.pop();\n }\n el...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n pair<int, string> helper(string s, int val, string req){\n stack<char>st;\n string rem = \"\";\n int count = 0;\n for(int i=0; i<s.size(); i++){\n if(s[i] == req[1]){\n if(!st.empty() && st.top() == req[0]){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\nprivate:\n //function for counting pairs\n string removevalid(string s,int ch)\n { stringstream ss;\n char b,a;\n b='b'-ch;\n a='a'+ch;\n stack<char>st;\n int n=s.size();\n for(int i=0;i<n;i++)\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int recur(string s, int idx, int x, int y) {\n if (idx >= s.length())\n return 0;\n int max1 = 0;\n if (idx + 1 < s.length()) {\n if (s[idx] == 'a' && s[idx + 1] == 'b') {\n max1 = max(max1, x + recur(s, idx + 2, x, y)...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int update(string &s, int val, int point)\n {\n int points = 0;\n string k = s;\n stack<int>st;\n if(val==0)\n {\n for(int i=0;i<k.length();i++)\n {\n while(!st.empty() && k[st.top()] == 'a' && k[i] ==...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int ans=0;\n\n string solvey(string s,int y)\n {\n stack<char> st;\n string ss;\n \n for(auto k:s)\n {\n if(st.size()==0) \n {\n st.push(k);\n }\n else if(k=...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n\n stack<pair<char,int>> st;\n int sum=0;\n char ch1='a',ch2='b';\n\n if(x<y){\n ch1='b';\n ch2='a';\n int w=x;\n x=y;\n y=w;\n }\n\n fo...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int removeSubstrings(string s, int x, int y) {\n // Function to calculate maximum points\n int maxPoints = 0;\n\n // Helper function to remove a specific substring and calculate points\n auto removeSubstr = [&](string &str, const string &sub, int points) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int score(string& s, char first, char second, int points){\n stack<int> sk;\n int current = 0;\n for(char &c:s){\n if(!sk.empty() && sk.top() == first && c == second){\n current += points;\n sk.pop();\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int ret;\n\n string reverseStringstr(string str) {\n string ret = \"\";\n int n = str.length();\n for (int i = n - 1; i >= 0; i--) {\n ret += str[i];\n }\n return ret;\n }\n\n string removeABPattern(string str, int val) {...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int solve(string s,string &t)\n {\n int ans=0;\n\n //for \"ab\"\n // f=\"a\"=t[0]\n // s=\"b\"=t[1]\n stack<int> st;\n\n for(int i=0;i<s.size();i++)\n {\n if(s[i]==t[1] && st.size() && st.top()==t[0])\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n stack<int>st;\n int ans=0;\n int n=s.size();\n string str=\"\";\n char a='a',b='b';\n if(y>x){\n swap(a,b);\n swap(x,y);\n }\n vector<int>vis(n+1,0);\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int topScore=0,botScore=0,maxi=0;\n string top,bot;\n if(x>y){\n top=\"ab\";\n topScore=x;\n bot=\"ba\";\n botScore=y;\n }else{\n top=\"ba\";\n ...
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n if(n<=0){\n return false;\n }\n int m = n-1;\n if((n&m) == 0) return true;\n else return false;\n }\n};", "memory": "7100" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n return n > 0 && (n & (n - 1)) == 0;\n }\n};", "memory": "7200" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n int ans=1;\n for(int i=0;i<=30;i++){\n if(ans==n){\n return true;\n }\n if((ans)>=INT_MAX/2){\n break;\n }\n else{\n ans=ans*2;\n ...
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "// Dhairya Kumar Singh\n\nclass Solution \n{\npublic:\n bool isPowerOfTwo(int n) \n {\n if(n==0) return false;\n while(n%2==0) n=n/=2;\n return n==1?true:false;\n }\n};", "memory": "7300" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n\n return (n > 0) && ((n & (n - 1)) == 0);\n \n }\n};", "memory": "7300" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n if(n==0) return false;\n\n while(n>0){\n if(n==1) return true;\n if(n%2!=0) break;\n n/=2;\n }\n return false;\n }\n};", "memory": "7400" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n for(int i =0; i<31;i++){\n int ans = pow(2,i);\n if(ans == n)return true;\n }\n return false;\n }\n};", "memory": "7400" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
1
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n if(n<=0) return 0;\n else if(n==1) return 1;\n else if(!(n&(n-1))) return 1;\n else return 0;\n }\n};", "memory": "7500" }
231
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
1
{ "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n if(n<=0) return 0;\n if(!(n & n-1)) return 1;\n return 0;\n }\n};", "memory": "7500" }
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n int ones = 0;\n for (long long m = 1; m <= n; m *= 10)\n ones += (n/m + 8) / 10 * m + (n/m % 10 == 1) * (n%m + 1);\n return ones;\n }\n};", "memory": "7100" }
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution { \npublic:\n int countDigitOne(int n) {\n int ret = 0;\n for(long long int i = 1; i <= n; i*= (long long int)10){\n int a = n / i;\n int b = n % i;\n int x = a % 10;\n if(x ==1){\n ret += (a / 10) * i + (b + 1);\n }\n els...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution { \npublic:\n int countDigitOne(int n) {\n int ret = 0;\n for(long long int i = 1; i <= n; i*= (long long int)10){\n int a = n / i;\n int b = n % i;\n int x = a % 10;\n if(x ==1){\n ret += (a / 10) * i + (b + 1);\n }\n els...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution { \npublic: \n int countDigitOne(int n) { \n long long count = 0; \n long long factor = 1; // This represents the current digit place (1, 10, 100, ...) \n \n while (factor <= n) { \n long long lowerNumbers = n - (n / factor) * factor; // Number...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution {\npublic:\n vector<int> dp;\n vector<int> count;\n int solve(int n){\n int dig=0;\n int t = n;\n while(t>0){\n dig++;\n t = t/10;\n }\n int ans=0;\n if (n==0) return 0;\n if (dig == 1) return 1;\n ans += ...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
0
{ "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n long long count = 0;\n long long factor = 1;\n while (factor <= n) {\n // Calculate the parts\n long long lowerNumbers = n - (n / factor) * factor;\n long long currentDigit = (n / factor) % 10;...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
1
{ "code": "class Solution {\npublic:\n string convert(int n) {\n string ret = \"\";\n\n while (n > 0) {\n ret = char(48 + n % 10) + ret; \n n /= 10;\n }\n\n if (ret.size() == 0) {\n ret = \"0\";\n }\n\n return ret;\n}\n\nint countDigitOne(int n) {\n long long ans = 0...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
1
{ "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n int ans = 0;\n long long p = 1;\n while(p <= n)\n {\n int a = n / p;\n int b = n % p;\n int d = a % 10;\n if(d == 0)\n ans += (a / 10) * p;\n else if...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
2
{ "code": "class Solution {\npublic:\n int solve(string &num, int index, int less, int count, vector<vector<vector<int>>> &dp){\n if(index==num.size()) return count;\n\n if(dp[index][less][count]!=-1) return dp[index][less][count];\n\n int limit=9;\n if(less==0) limit=num[index]-'0';\n\...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
2
{ "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n int ans = 0;\n if(n <= 0) return 0;\n if(n <= 9) return 1;\n\n unordered_map<int,int> m;\n m[9] = 1;\n\n for(int i = 9 ; i <= (INT_MAX - 9)/10 ; i = i*10 + 9){\n m[i*10+9] = m[i]*10 + (i+1);\n ...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
3
{ "code": "class Solution {\npublic:\n\n int factorial(int D) {\n if(D == 0)\n return 1;\n\n int prod1 = 1;\n for(int k=1; k <= D; k++)\n prod1 *= k;\n \n return prod1;\n }\n\n int solve(int D) {\n\n if(D == 1)\n return 1;\n\n ...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
3
{ "code": "class Solution {\npublic:\n\n int countDigitOne(int n) {\n int ans = 0;\n if(n == 0) return 0;\n if(n <= 9) return 1;\n unordered_map<int, int> mp;\n mp[9] = 1;\n\n for(int i=9; i<(INT_MAX-9)/10; i=i*10+9) {\n mp[i*10+9] = mp[i]*10 + (i+1);\n }...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
3
{ "code": "class Solution {\npublic:\n bool flag;\n int countDigitOne(int n) {\n int ans = 0;\n if(n == 0) return 0;\n if(n <= 9) return 1;\n flag = true;\n unordered_map<int, int> mp;\n if(flag) {\n mp[9] = 1;\n\n for(int i=9; i<(INT_MAX-9)/10; i=...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
3
{ "code": "vector<int> powers{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};\nclass Solution {\npublic:\n int recur(int index, bool flag, string &num, vector<vector<int>> &dp) {\n if(index == num.size()) return 0;\n if(dp[index][flag] != -1) return dp[index][flag];\n ...
233
<p>Given an integer <code>n</code>, count <em>the total number of digit </em><code>1</code><em> appearing in all non-negative integers less than or equal to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 13 <strong>Output:</strong> 6 </pre> ...
3
{ "code": "vector<int> powers{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};\nclass Solution {\npublic:\n int recur(int index, bool flag, string &num, vector<vector<int>> &dp) {\n if(index == num.size()) return 0;\n if(dp[index][flag] != -1) return dp[index][flag];\n ...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 int init = [] {\n std::...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 int init = [] {\n ios_b...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
0
{ "code": "static const int _ = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\nclass Solution\n{\npublic:\n bool isPalindrome(ListNode *head)\n {\n if(nullptr == head || nullptr == head->next) \n {\n return true;\n }\n\n ...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
0
{ "code": "class Solution {\n ListNode* reverse(ListNode* head, ListNode* s){\n if(head==s) return head;\n ListNode* curr=reverse(head->next,s);\n head->next->next=head;\n head->next=NULL;\n return curr;\n }\npublic:\n bool isPalindrome(ListNode* head) {\n if(head->n...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 {\n public:\...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
0
{ "code": "class Solution {\npublic:\n ListNode* reverselist(ListNode* head){\n ListNode* prev,*curr,*Next;\n prev = NULL;\n curr = head;\n Next = head;\n while(curr){\n Next = curr->next;\n curr->next = prev;\n prev = curr;\n curr = Ne...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 */\nListNode *findMid(ListNode ...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 */\n#pragma GCC optimize(\"O3,u...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
1
{ "code": "class Solution {\npublic:\n bool isPalindrome(ListNode* head) {\n if (head == NULL || head->next == NULL) return true;\n \n // Step 1: Find the middle of the linked list using two pointers\n ListNode *slow = head, *fast = head;\n \n while (fast->next != NULL && ...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
1
{ "code": "class Solution {\npublic:\n ListNode* reverse(ListNode* head) {\n ListNode* curr = head;\n ListNode* prev = nullptr;\n ListNode* next = nullptr;\n\n while (curr != nullptr) {\n next = curr->next;\n curr->next = prev;\n prev = curr;\n ...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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 {\n ListN...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...
234
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
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...