id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if(s.empty())\n {\n return std::string();\n }\n\n size_t n = s.size();\n std::vector<int> table(n * n);\n\n for(size_t i = 0; i < n; ++i)\n {\n table[(n * i) + i] = 1... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.length();\n if(n<=1) return s;\n int max_len = 1;\n string max_str = \"\";\n max_str+=s[0];\n string str = \"#\";\n for(int i=0;i<n;i++) {\n str = str + s[i] + '#';\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string maxStr = \"\";\n for(int i = 0 ; i < s.size(); i++){\n string longestPalCenteredAtI = longestPalindromeCenteredHere(s,i);\n maxStr = longestPalCenteredAtI.size() > maxStr.size() ? longestPalCent... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "/*class Solution {\npublic:\n\n int& getBool(vector<int>& mat, int row,int col, int len){\n return mat[col+row*len];\n }\n\n\n string longestPalindrome(string s) {\n int len = s.size();\n int max = -1;\n string longest;\n //satrt index=row, end index = col\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "/*class Solution {\npublic:\n\n int& getBool(vector<int>& mat, int row,int col, int len){\n return mat[col+row*len];\n }\n\n\n string longestPalindrome(string s) {\n int len = s.size();\n int max = -1;\n string longest;\n //satrt index=row, end index = col\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n map <int, set <int>> solutions;\n for(int i = 0; i < n; i++){\n solutions[1].insert(i);\n }\n int maxlen = 1;\n int lastindex = 0;\n for(int i = 0; i < n-1; ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.length();\n string str = \"#\";\n for(int i = 0; i < n; i++) str = str + \"\" + s[i] + \"#\";\n n = str.length();\n vector<vector<bool>> v(n, vector<bool>(n));\n for(int i = 0; i < n; i... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n // check for bestcases, s already palindrome itself\n string resultMaxPalindrome = s;\n reverse(resultMaxPalindrome.begin(), resultMaxPalindrome.end());\n\n if(s == resultMaxPalindrome) {\n return s... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool pallindrome(int i, int j, string &s) {\n while(i <= j) {\n if(s[i] != s[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n string longestPalindrome(string s) {\n vector<pair<int, in... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "/*\n\"abcba\"\n\"aaaaa\"\n\"cbbd\"\n\"aacabdkacaa\"\n*/\n\nclass Solution {\npublic:\n string longestPalindrome(string s) {\n int **v=(int **)malloc(s.size()*sizeof(int *));\n int max=0,ii=0,jj=0;\n\n if(s.length()==1)\n return s;\n if(s.length()==2)\n {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\n int **d;\npublic:\n string longestPalindrome(string s) {\n int n = s.length();\n int i,m;\n d = new int*[n];\n int a,b;\n for (i = 0; i < n; ++i){\n d[i] = new int[n];\n memset(d[i], 0, n*sizeof(int));\n }\n for (... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "bool isPalindrome(string &s, int start, int end){\n while(s[start] == s[end]){\n if( start > end ) return true;\n start++;\n end--;\n } \n \n return false;\n}\n\nstring findPalindrome(string &s, int **arr){\n int i = 0;\n int len = s.size();\n int j = len-1;\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string ans;\n bool isPalin(int l, int r, string &s){\n int x = l, y = r;\n while(l <= r) if(s[l++] != s[r--]) return false;\n if(ans.length() <= y - x + 1){\n ans = s.substr(x, y - x + 1);\n }\n return true;\n }\n void fu... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string ans;\n bool isPalin(int l, int r, string &s){\n int x = l, y = r;\n while(l <= r) if(s[l++] != s[r--]) return false;\n if(ans.length() <= y - x + 1){\n ans = s.substr(x, y - x + 1);\n }\n return true;\n }\n void fu... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n int f(int i, int j, vector<vector<int>>&dp, string &s){\n if(i >= j) return 1;\n\n if(dp[i][j] != -1) return dp[i][j];\n\n if(s[i] == s[j]) dp[i][j] = f(i + 1, j - 1, dp, s);\n else dp[i][j] = 0;\n\n return dp[i][j];\n\n\n }\n string l... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool isPalin(string s,int n){\n for(int i=0;i<=n/2;i++){\n if(s[i]!=s[n-i-1]) return false;\n }\n return true;\n }\n string longestPalindrome(string s) {\n // if(s.size()<=1) return s;\n // int maxL=1,n=s.length();\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if(s.size()==1) return s;\n if(s.size()==2){\n if(s[0]==s[1]) return s;\n else s[0];\n }\n vector<vector<int>> dp(s.size(),vector<int>(s.size(),0));\n int max=0; string ans=\"\";\n... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool find(int left, int right, string &s, string &ans, vector<vector<int>> &dp) {\n if (left > right) return false;\n if (left == right) {\n return true;\n }\n\n if(dp[left][right] != -1) return dp[left][right];\n\n bool isPalindr... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int len=s.length();\n int max_len=1;\n int start=0;\n vector<vector<int>>dp(len,vector<int>(len,0));\n for(int i=0;i<len;i++)\n {\n dp[i][i]=1;\n }\n for(int i=0;i<... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n vector<vector<int>> dp(n, vector<int>(n, 0));\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n int l = i + j;\n if(l < n){\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n unordered_map < char, vector<int>> hash;\n\n for (int i = 0; i < s.size(); i++) {\n hash[s[i]].push_back(i);\n }\n\n string maxPalindrome = \"\";\n int maxSize = 0;... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\nprivate:\n bool ispalindrome(string s){\n int i=0,j=s.length()-1;\n while(i<j){\n if(s[i]!=s[j])\n return false;\n i++,j--;\n }\n return true;\n }\npublic:\n string longestPalindrome(string s) {\n if(s.length()==1) return s;\n string subs... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string getsubstr(string s,int i,int j)\n {\n string ans=\"\";\n for(int k=i;k<=j;k++){ans+=s[k];}\n return ans;\n }\n string longestPalindrome(string s) {\n int n=s.length();\n vector<vector<int>> dp(n,vector<int>(n,0));\n fo... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string longest=\"\";\n int n=s.length();\n int j;\n\n for(int i=0;i<n;i++){\n j=n-1;\n\n string subs=\"\";\n\n string subsrev=\"\";\n\n while(i<j){\n\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "/*\nSo The first thing that comes to my mind is-\nCan have 2 pointers starting from the 0 index going until n-1 increasing by 2 everytime \n(can't be coz there can be a palindrome of even or odd size so I'll increase by 1 only)\nj starts from i + 1 everytime----> i goes until n-2\nSoo this is just brute f... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "/*\nSo The first thing that comes to my mind is-\nCan have 2 pointers starting from the 0 index going until n-1 increasing by 2 everytime \n(can't be coz there can be a palindrome of even or odd size so I'll increase by 1 only)\nj starts from i + 1 everytime----> i goes until n-2\nSoo this is just brute f... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n\n void buildlps(string &a , vector<int> &lps){\n int n=a.size();\n int i=1;\n int len=0;\n while(i<n){\n if(a[i]==a[len]){\n lps[i]=len+1;\n i++;\n len++;\n }\n else {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n int check(string s)\n {\n int l=s.length();\n for(int i=0;i<l/2;i++)\n if(s[i]!=s[l-i-1])\n return 0;\n return 1;\n }\n string longestPalindrome(string s) {\n string t=s;\n reverse(s.begin(),s.end());\n int m=s.... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n string rev_s = s; // 复制s\n reverse(rev_s.begin(), rev_s.end()); // 倒置s\n int max_len = 0, end_idx = 0;\n \n // 建立一个二维数组来存储公共子串长度\n vector<vector<int>> dp(n+1, vector<in... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n string rev_s = s; // 复制s\n reverse(rev_s.begin(), rev_s.end()); // 倒置s\n int max_len = 0, end_idx = 0;\n \n // 建立一个二维数组来存储公共子串长度\n vector<vector<int>> dp(n+1, vector<in... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution\n{\n public:\n\n bool solve(int i, int j, string &s, int n, vector<vector<int>>&dp)\n {\n\n if (i == n || j < 0) return 0;\n\n \n if(dp[i][j] != -1)\n return dp[i][j];\n if (i >= j)\n return true;\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\n\nprivate:\n bool check(int i, int j, string &s, vector <vector<int>> &dp){\n int n = s.size();\n\n if(i > j){\n return true;\n }\n\n if(dp[i][j] != -1) return dp[i][j];\n\n if(s[i] != s[j]){\n return dp[i][j] = false;\n }... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n // bool checkPalindrome(string &s, int i,int j){\n // while(i<=j){\n // if(s[i]==s[j]){\n // i++;\n // j--;\n // }else{\n // return false;\n // }\n // }\n // return true;\n /... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp; // Declare the dp vector here\n\n // Constructor to initialize the dp vector\n Solution() : dp(1001, vector<int>(1001, -1)) {}\n\n bool check(string &s, int i, int j) {\n if(i >= j) return 1;\n\n if(dp[i][j] != -1) return dp[i][... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n list<char> maxChars;\n for (int i = 0; i < s.size(); i++) {\n \n list<char> chars;\n int left = i;\n int right = i;\n chars.push_back(s[i]);\n \n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "#include <list>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n string longestPalindrome(string s) {\n string ans;\n ans.push_back(s[0]);\n list<char> tempAns;\n\n for (int i = 0; i < s.length() - 1; i++)\n {\n if (s[i] == s[i + 1]... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string s)\n{\n for (int i = 0; i < s.length(); i++)\n {\n if(s.at(i) != s.at(s.length() - i - 1))\n {\n return false;\n }\n }\n return true;\n}\n string longestPalindrome(string s) {\n int left, right;\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string getPalindrom(const string& s, int pos0, int pos1) {\n if (pos0 < 0) return \"\";\n if (pos1 >= s.size()) return \"\";\n if (pos0 > pos1) return \"\";\n\n string ps(s.begin() + pos0, s.begin() + pos1 + 1);\n\n //cout << \"ps \" << ps <... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string s){\n int n = s.size();\n int i=0,j=n-1;\n while(i<j){\n if(s[i] != s[j]){\n return false;\n }\n i++;j--;\n }\n return true;\n }\n string longestPalindrome(string... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool checkPalindrome(string str)\n {\n if (!str .size())\n {\n return true;\n }\n int sz = str.size();\n for (int i = 0; i <= sz / 2 - 1 ; i++)\n {\n if (str[i] != str[sz - i - 1])\n {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if (s.size() <= 1) \n return s;\n \n string ans = \"\";\n for (int i = 0; i < s.size(); i++) {\n string pal = checkBack(s.substr(i));\n if (pal.size() > ans.size()) {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int l, int r, string s){\n while(l < r){\n if(s[l] != s[r]){\n return false;\n }\n l++;\n r--;\n }\n return true;\n }\n\n string longestPalindrome(string s) {\n int ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string maxString=s.substr(0, 1);\n for (int i=1; i<s.size()-maxString.size()/2; i++){\n int j=1;\n if (s[i-1]==s[i]){\n string subEven=s.substr(i-1, 2);\n while (i-1-j>=0 ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "// longest_palindromic_substr\nclass Solution {\npublic:\n int checkPara(string s, int left, int right, bool &loop) {\n if (loop) {\n if (((left-1)<0 && s[left]!=s[right+1]) || ((right+1)>=s.size() && s[left-1]!=s[right]))\n loop = false;\n if ((left-1)>=0 && ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n string res = \"\";\n\n for(int i = 0; i < n; i++) {\n string cur(1,s[i]);\n int l = i-1;\n int r = i+1;\n\n while(l >= 0 && r < n && s[l] == s[r]) {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n string res = \"\";\n\n for(int i = 0; i < n; i++) {\n string cur(1,s[i]);\n int l = i-1;\n int r = i+1;\n\n while(l >= 0 && r < n && s[l] == s[r]) {\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if (isPalindrome(s)) return s;\n\n int n = s.length();\n string soln{};\n for (int i{}; i < n; ++i) {\n string tmp{};\n for (int j{i}; j < n; ++j) {\n tmp += s[j];\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string s){\n int n = s.size();\n for(int i = 0;i<n/2;i++)\n if(s[i] != s[n-1-i])\n return false;\n return true;\n }\n string longestPalindrome(string s) {\n string ans = \"\";\n for(int i = 0... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string ans=\"\";\n ans+=s[0];\n int maxi=1;\n\n for(int i =1 ; i<s.size()-1 ; i++){\n // checking for odd\n int start = i-1;\n int end=i+1;\n string right=\"\";\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int left = 0;\n int right = 0; \n string max = \"\";\n string temp = \"\";\n\n for (int i = 0; i < s.length(); i++) {\n left = i - 1;\n right = i + 1;\n temp = s[i];\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string odd(string s){\n string current = \"\";\n string ans =\"\";\n for(int i = 0 ;i <s.length() ; i++){\n int j= i;\n int k =i;\n while( j >= 0 && k < s.length() && s[j] == s[k]){\n current = s.substr(j , k - j +1);\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n\n //init the string with #\n string str = \"#\";\n for(int i = 0; i < s.length(); i++){\n str = str + s[i] + \"#\";\n }\n\n //init some variable\n int* LPS = new int[str.length()];\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n \n int m=0;\n string st=\"\";\n int n=s.length();\n int i=0,j=s.length()-1;\n \n while(i<n)\n {\n if(s[i]==s[j])\n {\n s... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.length();\n\n // solution - 1 - brute force;\n\n // int i=0;\n // int maxLen = 0;\n // string pal;\n // for(i=0;i<n;i++){\n // for(int j=i;j<n;j++){\n // strin... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string ans = \"\";\n\n unordered_map<char, vector<int>> map;\n\n for (int i = 0; i < s.length(); i++) {\n map[s[i]].push_back(i);\n }\n\n for (auto pair : map) {\n vector<int> vec ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string ans = \"\";\n\n unordered_map<char, vector<int>> map;\n\n for (int i = 0; i < s.length(); i++) {\n map[s[i]].push_back(i);\n }\n\n for (auto pair : map) {\n vector<int> vec ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\n bool isPalindrome(const std::string& s, int start, int end) {\n while (start < end) {\n if (s[start] != s[end]) {\n return false;\n }\n start++;\n end--;\n }\n return true;\n }\n\n void formstring(st... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\n bool isPalindrome(const std::string& s, int start, int end) {\n while (start < end) {\n if (s[start] != s[end]) {\n return false;\n }\n start++;\n end--;\n }\n return true;\n }\n\n void formstring(st... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n void solve(string s, int i, int j, string& str, int& len) {\n \n if (i < 0 || j >= s.length()) {\n return;\n }\n \n \n if (s[i] == s[j]) {\n if (len < j - i + 1) {\n str = s.substr(i, j - i + 1);\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if (s.empty()) return \"\";\n vector<vector<int>> dp(s.size(), vector<int>(s.size(), -1));\n return f(s, 0, s.size() - 1, dp);\n }\n\nprivate:\n string f(string &s, int start, int end, vector<vector<int>>& dp) ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int len = s.length();\n string ans = \"\";\n ans+=s[0];\n int i, j;\n for(int k=0;k<len;k++){\n i = k;\n j = k;\n // cout<<s[i]<<\" \"<<s[j]<<endl;;\n while(i... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string biggie=\"\";\n \n for(int i=0;i<s.size();i++){\n //case of odd,s[i],middle\n string shortie=\"\";\n shortie+=s[i];\n int j=1;\n while((j+i)<s.size()&&(i-j... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n pair<pair<int,int>,int> sol(string& s,int i,int j,vector<vector<pair<pair<int,int>,int>>>&dp){\n if(j<i) return {{0,0},1};\n if(i==j) {\n return {{i,i},1};\n }\n if(dp[i][j].second!=-1) return dp[i][j];\n pair<int,int>t={0,0};\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if (s.length() <= 1) {\n return s;\n }\n\n string longestStr = s.substr(0, 1);\n vector<vector<bool>> dp(s.length(), vector<bool>(s.length(), false));\n \n for (int i = 0; i < s.length... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool IsPalindromicSubstring(const string &s)\n {\n //cout << s << endl;\n int dwLength = s.length();\n for (int i = 0; i < dwLength / 2; i++)\n {\n if (s[i] != s[dwLength - 1 - i])\n {\n return false;\n ... |
5 | <p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = ... | 3 | {
"code": "class Solution {\npublic:\n bool IsPalindromicSubstring(const string &s)\n {\n int i = 0;\n int j = s.length() - 1;\n while (i < j)\n {\n if (s[i] != s[j])\n {\n return false;\n }\n i++;\n j--;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "// P A Y P A L I S H I R I N G\n\n// 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n// P A H N \n// A P L S I I G\n// Y I R\n\n// -->\n\n// 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n// P A H N \n// A P L S I I G\n// Y I R\n\n// P A H N A P L... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "// P A Y P A L I S H I R I N G\n\n// 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n// P A H N \n// A P L S I I G\n// Y I R\n\n// -->\n\n// 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n// P A H N \n// A P L S I I G\n// Y I R\n\n// P A H N A P L... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1)\n {\n return s;\n }\n \n int zagSize = (numRows * 2) - 2;\n string ret(s);\n int counter = 0;\n // Gather the first row\n for(int i = 0; i < s.... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1 || s.size() <= numRows) return s;\n int n = s.size();\n int freq = (numRows - 1) * 2;\n int offset = 0;\n string res;\n res.reserve(s.size());\n for (int i = 0; i < numRows; i++) {\n offset = (... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string ans;\n int p=0;\n int k=0;\n while(p<numRows){\n int iter=p;\n while(iter<s.length()){\n if(p!=0 && p!=numRows-1 && iter-k>=0){\n ans+=s[iter-k];\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) return s;\n string ans;\n int group = 2 * numRows - 2;\n for (int i = 1; i <= numRows; ++i) {\n int interval = i == numRows ? group : 2 * numRows - 2 * i;\n int idx =... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int n = s.length();\n string output = \"\";\n if(n==1 || numRows==1) return s;\n int space = 2*numRows -2;\n for(int i=0;i<numRows;i++){\n if(i==0 || i ==numRows-1){\n for(i... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int n = s.length();\n string output = \"\";\n if(numRows==1) return s;\n int space = 2*numRows -2;\n for(int i=0;i<numRows;i++){\n if(i==0 || i ==numRows-1){\n for(int j = i... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int n) {\n if (n == 1) return s;\n string res=\"\";\n string ds[n];\n int t = 0;\n bool flag = true;\n for(int i=0;i<s.size();i++){\n ds[t]+=s[i];\n if(flag) t++;\n else t--;\n... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) return s;\n char final[numRows][s.length()];\n memset(final, ' ', sizeof(final));\n\n\n int count = 0;\n int col = 0;\n int last = -1;\n bool going_down = true;\n\n\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int num_rows) {\n if(num_rows == 1)\n return s;\n\n const auto stride = num_rows + (num_rows - 2);\n std::stringstream strm;\n for(auto i = 0UL; i < num_rows; ++i) {\n auto c = i;\n while(c ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1)\n return s;\n\n stringstream ss;\n for (int row = 0; row < numRows; ++row) {\n int idx;\n int cnt = 0;\n while(true){\n idx = cnt * (2*(nu... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<pair<char, int>> dp(s.size());\n int i=0, currRow=1;\n\n bool up = false, start=true;\n if(numRows==1) return s;\n while(i<s.size()){\n dp[i].first = s[i];\n dp[i].second... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int n = s.size();\n if(n==0 || n==1) return s;\n if(numRows==0 || numRows==1) return s;\n // tc : numRows * n;\n int k = 2*numRows - 2;\n string ans=\"\";\n for(int i=1; i<k/2; i++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n //Boundary Case:\n if(numRows == 1 || numRows==s.size()) return s;\n\n //Normal Case Handling:\n vector<string> rows(numRows);\n int size = s.size(),j=0,inc=1;\n \n\n for(int i=0; i<siz... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n std::string convert(const std::string& s, int numRows) {\n // Edge case: if numRows is 1 or s length is less than numRows\n if (numRows == 1 || numRows >= s.length()) {\n return s;\n }\n \n std::vector<std::string> rows(numRows);\... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1 || s.empty() || numRows >= s.size()){\n return s;\n }\n // consider vector of strings for each row \n vector<string>row(numRows);\n\n int currRow = 0;\n bool goDown... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 0 | {
"code": "class Solution {\npublic:\n\tstring convert(string s, int numRows) {\n\t\tvector<string> container(numRows);\n\t\tint unit = 2 * numRows - 2;\n\n\t\tif(unit == 0) {\n\t\t\treturn s;\n\t\t}\n\t\tfor (int i = 0; i < s.size(); i++) {\n\t\t\tconst int position = i % unit;\n\t\t\tconst int amount = i / unit;\n\... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 1 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n\n // int len = s.length();\n // char ch[100][100];\n // for (int i=0;i<100;i++)\n // {\n // for (int j=0;j<100;j++)\n // {\n // ch[i][j] = ' ';\n // }\n // } \n // in... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 1 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1)\n {\n return s;\n }\n vector<string>zigzag(numRows);\n string ans=\"\";\n int i=0;\n int row=0;\n int dir=1;\n while(true)\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 1 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1) return s;\n vector<string> rows(min(numRows,int(s.size())));\n int currentRow=0;\n bool goingDown=false;\n\n for(char c:s){\n rows[currentRow]+=c;\n if(currentRow... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 1 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) {\n return s;\n }\n \n int x = 0;\n int y_dir = -1;\n\n vector<string> vc(min(numRows, (int)s.size()));\n\n for(const char c: s) {\n vc[x] += c;\n... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 2 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<string>tmp(numRows,\"\");\n if(numRows==1){\n return s;\n }\n bool inc=true;\n int ind=0;\n for(int i=0;i<s.length();i++){\n if(ind==numRows-1){\n i... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 2 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int rows = 0;\n bool flip = false;\n vector<string> ret(s.length(),\"\");\n\n for(int i = 0; i< s.length(); ++i) {\n ret[rows] += s[i];\n if(flip) {\n rows -= 1;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 2 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n \n \n int n=s.size();\n \n if(numRows==1){\n return s;\n }\n \n// making an array\n // int k=numRows;\n // string arr[numRows]= {\"\"};\n // std:... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 2 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1 || numRows >= s.length()) {\n return s;\n }\n\n int idx = 0, d = 1;\n vector<vector<char>> rows(numRows);\n\n for (char c : s) {\n rows[idx].push_back(c);\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 2 | {
"code": "/*\nOriginal solution. JV.\n*/\n\n#define ONE (1)\n\nclass Solution {\npublic:\n string convert(string s, int rows) {\n vector<vector<char>> auxiliary(rows, vector<char>(0, 0));\n\n int n = s.length();\n\n if(rows == ONE || n < rows){\n return s;\n }\n\n int... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1){\n return s;\n }\n vector<vector<char> > rows(numRows);\n int cur_row = 0;\n int dir = 1;\n for(int i = 0; i < s.size(); i++){\n rows[cur_row].push_back(... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) return s; // No zigzag required for 1 row.\n\n vector<vector<char>> temp(numRows); // Vector of rows to store characters.\n string ans = \"\";\n int r = 0; // Row pointer.\n int ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1) return s;\n string ans=\"\";\n vector<vector<int>> m(numRows);\n int down=0;\n bool d=true;\n\n for(int i=0;i<s.length();i++){\n if(d){\n m[down].push_... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1) return s;\n string ans=\"\";\n vector<vector<int>> m(numRows);\n int down=0;\n bool d=true;\n\n for(int i=0;i<s.length();i++){\n if(d){\n m[down].push_... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<string> arr;\n string ret;\n if (numRows == 1) {\n return s;\n }\n for (int i = 0; i < numRows; i++) {\n arr.push_back(string());\n }\n int row = 0;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1)\n return s;\n unordered_map<int,string> m;\n int row=0, flag=1;\n \n for(int i=0;i<s.length();i++){\n if(row<0)\n row=1, flag=1;\n else if(row>numRows-1)\... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1){\n return s;\n }\n unordered_map<int, string> umap;\n for(int i = 0; i < numRows; i++){\n umap[i] = \"\";\n }\n int sign = 1;\n int index = 0;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.