id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "int dp[1001][1001];\nint solve(string &s,int i,int j){\n if(i==j){\n return 0;\n }\n\n if(i>j){\n return 0;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n int ans=0;\n if(s[i]==s[j]){\n ans=solve(s,i+1,j-1);\n }else{\n ans=1+min(solve(s,i+1,j)... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "int t[1001][1001];\nclass Solution {\npublic:\n int lcs(string s,string s1,int n,int m){\n for(int i=0;i<=n;i++){\n for(int j=0;j<=m;j++){\n if(i==0||j==0)\n t[i][j]=0;\n }\n }\n for(int i=1;i<=n;i++){\n for(int j=1;j<=m;j++){\n if(s1[i-1]==s[j-1]){\n t[i][j]=... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int LCS(string X, string Y){\n int m=X.length();\n int t[1001][1001] = {0};\n for(int i=1;i<=m;i++){\n for(int j=1;j<=m;j++){\n if(X[i-1] == Y[j-1]) t[i][j] = 1+ t[i-1][j-1];\n else t[i][j] = max(t[i-1][j] , t[i][j... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int t[1001][1001];\n int solve2(int i, int j, string& s)\n {\n if (i>j) return 0;\n\n if (i==j) return 1;\n\n if (t[i][j] != -1) return t[i][j];\n if(s[i] == s[j]) return t[i][j] = (2+solve2(i+1, j-1, s));\n\n return t[i][j] = max(solv... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n int n = s.size();\n string s2;\n for(int i=n-1;i>=0;i--){\n s2 = s2 + s[i];\n }\n vector<int>prev(n+1,0);\n vector<int>curr(n+1,0);\n for(int i=1;i<=n;i++){\n for(int j=1;j<... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\nint dp[1001][1001];\nint m;\n// int solve(string s1, string s2,int i,int j){\n// if(i==m || j==m) return 0;\n// if(dp[i][j]!=-1) return dp[i][j];\n// if(s1[i]==s2[j]) return dp[i][j]=1+solve(s1,s2,i+1,j+1);\n// else{\n// return dp[i][j]=0+max(solve(s1,s2,i+1,j... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n string t=\"\";\n int dp[s.size()+1][s.size()+1];\n for(int i=0;i<s.size();i++){\n t=t+s[s.size()-1-i];\n dp[0][i]=0;\n dp[i][0]=0;\n }dp[0][s.size()]=0;\n dp[s.size()][0]=0;\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "// using space optimisation \n\nclass Solution {\npublic:\n int minInsertions(string s) {\n string rev = \"\" ; \n int n = s.length(); \n for(auto it : s){\n rev = it + rev ; \n }\n\n int dp[n+1][n+1] ;\n for(int i=0 ; i<=n ; i++)\n for(int... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int t[501][501];\n int solve(string& s, string& rev, int n, int m) {\n if (n == 0 || m == 0) {\n return 0;\n }\n if(t[n][m] != -1){\n return t[n][m];\n }\n if (s[n - 1] == rev[m - 1]) {\n return t[n][m] = ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int f(int i, int j, string& s){\n if(i == j) return 1;\n if(i > j) return 0;\n\n if(dp[i][j] != -1) return dp[i][j];\n\n int take = INT_MIN;\n if(s[i] == s[j]){\n take = 2 + f(i+1,j-1,s);\n }\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "\n\nclass Solution {\npublic:\n int minInsertions(string s) {\n // Idea :\n // Divide the string in two halves, check LCS.\n\n int ns = s.size();\n\n // string s1 = s.substr(0, ns/2);\n string s2 = s;\n\n reverse(s2.begin(), s2.end());\n\n // cout << s1 <... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "\n\nclass Solution {\npublic:\n int minInsertions(string s) {\n // Idea :\n // Divide the string in two halves, check LCS.\n\n int ns = s.size();\n\n // string s1 = s.substr(0, ns/2);\n string s2 = s;\n\n reverse(s2.begin(), s2.end());\n\n // cout << s1 <... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][5005]; \n\n int solve(int l,int r,string &s)\n {\n if(l==r) return 1;\n if(l>r) return 0;\n if(dp[l][r]!=-1) return dp[l][r];\n\n if(s[l]==s[r]) return 2 + solve(l+1,r-1,s);\n\n int pushl = solve(l+1,r,s);\n int push... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][5005]; \n\n int solve(int l,int r,string &s)\n {\n if(l==r) return 1;\n if(l>r) return 0;\n if(dp[l][r]!=-1) return dp[l][r];\n\n if(s[l]==s[r]) return 2 + solve(l+1,r-1,s);\n\n int pushl = solve(l+1,r,s);\n int push... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][5005]; \n\n int solve(int l,int r,string &s)\n {\n if(l==r) return 1;\n if(l>r) return 0;\n if(dp[l][r]!=-1) return dp[l][r];\n\n if(s[l]==s[r]) return 2 + solve(l+1,r-1,s);\n\n int pushl = solve(l+1,r,s);\n int push... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][5005]; \n\n int solve(int l,int r,string &s)\n {\n if(l==r) return 1;\n if(l>r) return 0;\n if(dp[l][r]!=-1) return dp[l][r];\n\n if(s[l]==s[r]) return 2 + solve(l+1,r-1,s);\n\n int pushl = solve(l+1,r,s);\n int push... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][5005]; \n\n int solve(int l,int r,string &s)\n {\n if(l==r) return 1;\n if(l>r) return 0;\n if(dp[l][r]!=-1) return dp[l][r];\n\n if(s[l]==s[r]) return 2 + solve(l+1,r-1,s);\n\n int pushl = solve(l+1,r,s);\n int push... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n string t = s;\n reverse(t.begin(),t.end());\n if(s==t) return 0;\n\n int len = s.length();\n vector<vector<int>> dp(len + 1, vector<int>(len+1,0));\n\n for(int i = 1; i <= len; i++){\n for(in... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int ans(string &s,string &st,int i ,int j, vector<vector<int>>& dp)\n {\n if(i<0 || j<0)\n {\n return 0;\n }\n if(dp[i][j]!=-1)\n {\n return dp[i][j];\n }\n int nottake=max(ans(s,st,i-1,j,dp),ans(s,st,i... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string a) {\n string b = a;\n reverse(b.begin(),b.end());\n \n if(a==b)\n return 0;\n \n int n= a.size();\n vector<vector<int>> dp(n+1,vector<int> (n+1,-1));\n \n for(int i=0;i<=n;i++)... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n // If the string is already a palindrome, return 0\n if (is_palindrome(s)) {\n return 0; \n }\n\n int n = s.size();\n // Initialize the dp table with -1 to indicate uncomputed subproblems\n v... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "bool checkPalindrome(string s){\n int size = s.size()-1;\n for(int i = 0 ;i<=size;i++){\n if(i >= (size-i)) return true; \n if(s[i]!=s[size-i]) return false;\n else continue;\n }\n return true;\n}\nint getMinPalin(string& s,int F,int L,vector<vector<int>>& dp){\n if(F>=L... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "bool checkPalindrome(string s){\n int size = s.size()-1;\n for(int i = 0 ;i<=size;i++){\n if(i >= (size-i)) return true; \n if(s[i]!=s[size-i]) return false;\n else continue;\n }\n return true;\n}\nint getMinPalin(string& s,int F,int L,vector<vector<int>>& dp){\n if(F>=L... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string s){\n string t = s;\n reverse(s.begin(), s.end());\n return s == t;\n }\n\n int findLCS(string s1, string s2){\n int n1 = s1.size(); int n2 = s2.size();\n\n vector<vector<int> > dp(n1+1, vector<int> (n2+1, 0));... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int solve(string& s, int i, int j, vector<int>& dp) {\n if (i >= j) \n return 0;\n if (dp[i * s.size() + j] != -1) \n return dp[i * s.size() + j];\n if (s[i] == s[j]) \n return dp[i * s.size() + j] = solve(s, i + 1, j - 1,... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n bool palindrome(int i,int j,string s){\n if(i>=j) return 1;\n if(s[i]==s[j]) return palindrome(i+1,j-1,s);\n else return 0;\n }\n int f(int i,int j,string s,string t){\n if(i==0 || j==0) return 0;\n if(s[i-1]==t[j-1]) return 1+f(i-1,j-... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n const int n = s.size();\n std::vector<int> dp(n);\n for (auto i = n - 2; i >= 0; --i) {\n std::vector<int> new_dp(n);\n for (auto j = i + 1; j < n; ++j) {\n if (s[j] == s[i]) {\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\nint longestCommonSubsequence(string text1, string text2) {\n vector<vector<int>> dp(text1.size(), vector<int>(text2.size(),-1));\n // return solve(text1,text2,dp,0,0);\n int i,j;\n for(i=0;i<text1.size();i++)\n {\n for(j=0;j<text2.siz... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\nint longestCommonSubsequence(string text1, string text2) {\n vector<vector<int>> dp(text1.size(), vector<int>(text2.size(),-1));\n // return solve(text1,text2,dp,0,0);\n int i,j;\n for(i=0;i<text1.size();i++)\n {\n for(j=0;j<text2.siz... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n int n = s.size();\n string t = s;\n reverse(t.begin(),t.end());\n vector<int>prev(n+1,0);\n for(int i=1;i<=n;i++){\n vector<int>curr(n+1,0);\n for(int j=1;j<=n;j++){\n if(s... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n string t=s;\n reverse(s.begin(),s.end());\n int n=s.length();\n\tint m=t.length();\n\t//Write your code here\n\tint **dp=new int*[n+1];\n\tfor(int i=0;i<=n;i++)\n\t{\n\t\tdp[i]=new int[m+1];\n\n\t\tfor(int j=0;j<=m;j++)\n\t... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string t1) {\n string t2=t1;\n reverse(t2.begin(),t2.end());\n int n=t1.size();\n int m=t2.size();\n vector<int>prev(m+1, 0);\n for(int i1=1;i1<=n;i1++){\n vector<int>curr(m+1, 0);\n for(int i2=... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n int n = s.size();\n vector<int> pre(n + 1, 0);\n for(int i = 1; i < n + 1; i++) {\n vector<int> cur(n + 1, 0);\n for(int j = 1; j < n + 1; j++) {\n if(s[i - 1] == s[n - j])\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\nprivate:\nint tab(string text1, string text2,int n)\n {\n vector<int> dp(n+1,0);\n for(int i=0;i<=n;i++)\n {\n vector<int> curr(n+1,0);\n for(int j=0;j<=n;j++)\n {\n if(i==0 || j==0)curr[j]=0;\n else{\n... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\n int helper(int left, int right, const string &s, vector<vector<int>> &dp) {\n if (left >= right) return 0; // No insertions needed when indices cross or single character\n\n if (dp[left][right] != -1) return dp[left][right];\n\n if (s[left] == s[right]) {\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>>memory;\nint dp(int start,int end,string &s){\n\tif(start>=end)return 0;\n\tif(memory[start][end]!=-1)return memory[start][end];\n\tif(s[start]==s[end])return memory[start][end]=dp(start+1,end-1,s);\n\tint insert=1+dp(start+1,end,s);\n\tint del=1+dp(start,end... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 0 | {
"code": "#pragma GCC optimize(\"O3, unroll-loops\")\n#pragma GCC target(\"avx2, bmi, bmi2, lzcnt, popcnt\")\n\nstatic auto init = []() { \n cin.tie(nullptr) -> ios_base::sync_with_stdio(false); \n return nullptr; \n} ();\n\nclass Solution {\n public:\n int minInsertions(string s) {\n constexpr auto longes... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 2 | {
"code": "class Solution {\npublic:\n int minInsertions(string s) {\n \n int n = s.size();\n vector<vector<int>> dp(n+1,vector<int>(n+1,0));\n\n for(int i=1 ; i<=n ; i++)\n {\n for(int j=1 ; j<=n ; j++)\n {\n if(s[i-1] == s[(n-1)-(j-1)]){\n ... |
1,437 | <p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
<p> </p>
<p><s... | 2 | {
"code": "class Solution {\npublic:\n int minInsertions(string str1) {\n string str2;\n int n=str1.size();\n for(int i=0;i<n;i++){\n str2.push_back(str1[n-i-1]);\n }\n vector<vector<int>>dp(n+1,vector<int>(n+1,0));\n for(int i=1;i<=n;i++){\n for(int ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\")\n#include <limits>\n// \nauto init = []() {\n std::ios_base::sync_with_stdi... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\")\n#include <limits>\n\nauto init = []() {\n std::ios_base::sync_with_stdio(f... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL){\n return false;\n }\n if(he... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head == NULL)\n return false;\n ListNode *a = h... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL) return false;\n if(head->next==nullptr) return... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL || head->next==nullptr) return false;\n ListNod... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode *slow=head,*fast=head;\n if(head==NULL || head->next... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "class Solution {\npublic:\n bool hasCycle(ListNode *head) {\n // Check if the list is empty or has only one node (no cycle possible)\n if (head == NULL || head->next == NULL) {\n return false;\n }\n \n // Initialize two pointers: slow moves 1 step, fast move... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==nullptr)\n return false;\n ListNode* start=he... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n \n try {\n if (head == nullptr || head->next == nullptr)... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==nullptr)\n return false;\n ListNode* start=he... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode dummy;\n return HasCycleImpl( &dummy, head );\n }... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n vector <ListNode* > arr;\n while(head!=NULL){\n ar... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode* temp = head;\n vector<ListNode*>ans;\n while... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode* head) {\n ListNode* ptr;\n ptr = head;\n vector<ListNode*> temp;... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode* curr=head;\n vector<ListNode*>arr;\n while(c... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode *p=head;\n if(p==NULL||p->next==NULL)\n r... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n struct ListNode1 {\n ListNode* val;\n ListNode1 *next;\n ListNode1(ListNode* x) : val(x)... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n struct ListNode1 {\n ListNode* val;\n ListNode1 *next;\n ListNode1(ListNode* x) : val(x)... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n struct ListNode1 {\n ListNode* val;\n ListNode1 *next;\n ListNode1(ListNode* x) : val(x)... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head)\n {\n vector <int> prevs;\n int i = 0, n = 0;\n //int *... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head)\n {\n vector <int> prevs;\n int i = 0, n = 0;\n //int *... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head)\n {\n vector <int> prevs;\n int i = 0, n = 0;\n \n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution\n{\npublic:\n bool checkDuplicate( vector<ListNode *> &arr, ListNode *x)\n {\n for (int i = 0; i < arr.size(); i... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n std::vector<ListNode*> arr;\n bool check(ListNode *ptr)\n {\n for (int i=0;i<arr.size();i++){\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head == NULL) return false;\n set<ListNode*> stt;\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n std::set<ListNode*> visited;\n ListNode* curr = head;\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n set<ListNode *> l;\n ListNode *th=head;\n while(th)\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n set<ListNode *> visited;\n while (head != nullptr) {\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n set<ListNode*> nodesAddr;\n ListNode* curr = head;\n\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL)\n {\n return false;\n }\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n unordered_set<ListNode*> hash;\n while (head) { \n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode* head) {\n bool answer = false;\n std::unordered_set<ListNode *> visited... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n unordered_set<ListNode*> set;\n while (head) { \n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "#include <unordered_set>\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n // 해시 테이블을 사용하여 노드의 주소를 저장\n std:... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode* head) {\n unordered_set<ListNode*> hashSet;\n\n while (head != nullptr)... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n unordered_set<ListNode*> nodesAddr;\n ListNode* curr = head;\... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n unordered_set<ListNode*>st;\n while (head != nullptr){\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "#include <unordered_set>\n\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n std::unordered_set<ListNode*> visited; // Set to store visited nodes\n \n while (head != NULL) {\n if (visited.find(head) != visited.end()) { // Cycle found\n return ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n \n ListNode* temp = head;\n unordered_set<ListNode*> p... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n map<ListNode*,int>mpp;\n ListNode*temp=head;\n while(t... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL)\n {\n return false;\n }\n\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n map<ListNode *, int> mpp;\n ListNode*temp=head;\n whil... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n map<ListNode*,bool>table;\n ListNode*temp=head;\n whil... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n map<ListNode*, int>hash;\n ListNode* temp = head;\n\n ... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n std::set<ListNode*> s;\n ListNode *ptr = head;\n while... |
141 | <p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <code>pos</code> is used to den... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n ListNode* temp=head;\n map<ListNode*,int>mp;\n while(t... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 2 | {
"code": "#define opt() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\nclass Solution {\npublic:\n void reorderList(ListNode* head) {\n opt();\n if(head == NULL || head->next == NULL) return;\n\n ListNode * slow = head;\n ListNode * firstList = head; // TO MERGE THE FIRST HALF AND RE... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 2 | {
"code": "class Solution {\npublic:\n void reorderList(ListNode *head) {\n ListNode *slow = head, *fast = head->next;\n while (fast && fast->next) {\n fast = fast->next->next;\n slow = slow->next;\n }\n\n auto *mid = slow->next;\n slow->next = nullptr;\n // printf(\"mid=%d\\n\", mid->val... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
143 | <p>You are given the head of a singly linked-list. The list can be represented as:</p>
<pre>
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
</pre>
<p><em>Reorder the list to be on the following form:</em></p>
<pre>
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</s... | 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.