id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, s... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n if (nums1.size() > nums2.size()) {\n return findMedianSortedArrays(nums2, nums1);\n }\n\n int m = nums1.size();\n int n = nums2.size();\n int low = 0, high = m;\n\n while (l... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& a, vector<int>& b) {\n int n1 = a.size();\n int n2 = b.size();\n \n // Ensure that the first array is the smaller one\n if (n1 > n2) return findMedianSortedArrays(b, a);\n \n int low =... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n // Ensure nums1 is the smaller array.\n if (nums1.size() > nums2.size()) {\n return findMedianSortedArrays(nums2, nums1);\n }\n int m = nums1.size();\n int ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n int i = 0, j = 0, m1 = 0, m2 = 0;\n\n for (int count = 0; count <= (n + m) / 2; count++) {\n m2 = m1;\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n int i = 0,j = 0;\n int n = n1+n2;\n int ind2 = n/2;\n int ind1 = ind2-1;\n int count = 0;\n int ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n // 保證 nums1 的長度較小,這樣可以簡化後續邊界判斷\n if (nums1.size() > nums2.size()) {\n return findMedianSortedArrays(nums2, nums1);\n }\n\n int m = nums1.size();\n int n = n... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size(), n2 = nums2.size();\n if(n1>n2) return findMedianSortedArrays(nums2, nums1);\n int low = 0, high = n1;\n int left = (n1+n2+1)/2;\n int n = n1+n2;... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n if (nums2.size() < nums1.size())\n swap(nums1, nums2);\n\n int total = nums1.size() + nums2.size();\n int half = total / 2;\n int left = 0;\n int right = nu... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 0 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n int total = n1 + n2;\n int midIndex1 = (total - 1) / 2;\n int midIndex2 = total / 2; \n\n int i = 0, j =... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 1 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n1=nums1.size(),n2=nums2.size();\n // int i=min(nums1[0],nums2[0]);\n // int j=max(nums1[n-1],nums2[m-1]);\n if(n1>n2)\n return findMedianSortedArrays(nums2,nums1)... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 1 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int m = nums1.size();\n int n = nums2.size();\n \n // Ensure nums1 is the smaller array to minimize the number of binary search steps.\n if (m > n) {\n retu... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 1 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int m = nums1.size(), n = nums2.size();\n function<int(int, int, int)> f = [&](int i, int j, int k) {\n if (i >= m) {\n return nums2[j + k - 1];\n }\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 1 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& a, vector<int>& b) {\n int n1 = a.size(), n2 = b.size();\n //if n1 is bigger swap the arrays:\n if (n1 > n2) return findMedianSortedArrays(b, a);\n\n int n = n1 + n2; //total length\n int left = (n1 + n2 + 1) / 2; ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n int i = 0, j = 0;\n int lastIndex = -1;\n vector<int> result(n1 + n2, 0);\n\n while (i < n1 && j < n2) {\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int m = nums1.size(), n = nums2.size();\n function<int(int, int, int)> f = [&](int i, int j, int k) {\n if (i >= m) {\n return nums2[j + k - 1];\n }\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int>pendek = nums1; vector<int>panjang = nums2;\n \n if (panjang.size() < pendek.size()) swap(pendek,panjang);\n \n int sizePendek = pendek.size(), \n siz... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int totalSize = nums1.size() + nums2.size();\n int mid = totalSize / 2;\n vector<int> merged;\n int i = 0, j = 0;\n\n // Merge until we reach the middle\n while... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) \n {\n double m;\n vector<int> merged(nums1.size() + nums2.size());\n merge(nums1.begin(), nums1.end(), nums2.begin(), nums2.end(), merged.begin());\n m=(merged.size()/2);\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) \n {\n double m;\n vector<int> merged(nums1.size() + nums2.size());\n merge(nums1.begin(), nums1.end(), nums2.begin(), nums2.end(), merged.begin());\n m=(merged.size()/2);\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n\n vector<int> mergeArrays(vector<int>&nums1,vector<int>&nums2){\n vector<int> ans;\n int size1 = nums1.size();\n int size2 = nums2.size();\n int index1 = 0;\n int index2 = 0;\n while(index1<size1 || index2<size2){\n if(... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size(), m=nums2.size(), mid=(n+m)/2, i=0, j=0;\n vector<int>vec;\n while(i<n && j<m && vec.size()<=mid){\n if (nums1[i]<=nums2[j]) vec.push_back(nums1[i++]);\... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n vector<int>v;\n int i=0,j=0;\n while(i<n && j<m)\n {\n if(nums1[i]<=nums2[j])\n {\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int m=nums1.size();\n int n=nums2.size();\n vector<int>v;\n int i=0,j=0;\n while(i<m && j<n){\n if(nums1[i]<=nums2[j]){\n v.push_back(nums1[i... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans;\n int i=0;\n int j=0;\n while(i<nums1.size() && j<nums2.size()){\n int d1=i<nums1.size()?nums1[i]:0;\n int d2=j<nums2.size()?nums2[j]:0... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n vector<int>v;\n int i=0,j=0;\n while(i<n && j<m)\n {\n if(nums1[i]<=nums2[j])\n {\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int m = nums1.size(); \n int n = nums2.size();\n vector<int> ma(m + n); \n\n \n for(int i = 0; i < m; i++) {\n ma[i] = nums1[i];\n }\n for(int... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n vector<int> a = FindUnion(nums1, nums2, n, m);\n int k = a.size();\n if (k == 0) return 0.0; // No elements case\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector <int> temp;\n int i=0,j=0;\n int m=nums1.size(),n=nums2.size();\n while(i<m && j<n){\n if(nums1[i]<nums2[j]){\n temp.push_back(nums1[i++]);\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 2 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int> nums3;\n int i = 0, j = 0 ;\n int n1 = nums1.size();\n int n2 = nums2.size();\n\n while(i < n1 && j < n2 ){\n if(nums1[i] < nums2[j]) nums3.push... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n = nums2.size();\n float ans;\n for(int i=0; i<n; i++){\n nums1.push_back(nums2[i]);\n }\n sort(nums1.begin(),nums1.end());\n if(nums1.size()%2 ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n double ans;\n int n=nums1.size();\n int m=nums2.size();\n int s=n+m;\n vector<int>v(s);\n v=nums1;\n for(int i=0;i<m;i++)\n {\n v.push_back(num... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n nums1.insert(nums1.end(),nums2.begin(),nums2.end());\n sort(nums1.begin(),nums1.end());\n int l=nums1.size();\n int n=int(l/2);\n float s=0;\n if(l%2==1){\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n int n = nums2.size();\n float ans;\n for(int i=0; i<n; i++){\n nums1.push_back(nums2[i]);\n }\n sort(nums1.begin(),nums1.end());\n if(nums1.size()%2 ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "\nbool Is_odd(int in)\n{\n return in%2!=0;\n}\n\nbool Is_even(int in)\n{\n return in%2==0;\n}\nusing vec_it=vector<int>::iterator;\n\nclass Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n double retval=0;\n int d=0;\n \n i... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n // Get the sizes of both input arrays.\n int n = nums1.size();\n int m = nums2.size();\n\n // Merge the arrays into a single sorted array.\n vector<int> merged;\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int> sorted;\n sorted.insert(sorted.end(),nums1.begin(),nums1.end());\n sorted.insert(sorted.end(),nums2.begin(),nums2.end());\n sort(sorted.begin(),sorted.end());\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n // Get the sizes of both input arrays.\n int n = nums1.size();\n int m = nums2.size();\n\n // Merge the arrays into a single sorted array.\n vector<int> merged;\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n std::vector<int> result;\n\n for(int num : nums1) {\n result.push_back(num);\n }\n\n for(int num : nums2) {\n result.push_back(num);\n }\n\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int> sorted;\n sorted.insert(sorted.end(),nums1.begin(),nums1.end());\n sorted.insert(sorted.end(),nums2.begin(),nums2.end());\n sort(sorted.begin(),sorted.end());\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int>v;\n for(auto num:nums1){\n v.push_back(num);\n }\n for(auto num:nums2){\n v.push_back(num);\n }\n sort(v.begin(),v.end());\n ... |
4 | <p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p> </p>
<p><strong class="example">Example 1:<... | 3 | {
"code": "class Solution {\npublic:\n double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n vector<int>v;\n for(int i=0;i<nums1.size();i++){\n v.push_back(nums1[i]);\n }\n for(int i=0;i<nums2.size();i++){\n v.push_back(nums2[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 = ... | 0 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string &s) {\n\n int start=-1,end=-1;\n\n int n=s.length();\n int len=0;\n for(int i=0;i<n;++i){\n for(int j=n-1;j>=0;--j){\n if(s[i]==s[j] && len<(j-i+1)){\n int k=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 = ... | 0 | {
"code": "class Solution {\npublic:\n\n bool isPalindrome(const string& s, int i, int j) {\n while (i < j) {\n if (s[i] != s[j]) \n {\n return false;\n }\n i++;\n j--;\n }\n return true;\n }\n string longestPalindrome... |
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 = ... | 1 | {
"code": "class Solution {\npublic:\n bool palindromic(std::string& str) {\n int size = str.size();\n int size2 = size / 2;\n for (int i = 0; i < size2; i++) {\n if (str[i] != str[size - (i + 1)]) {\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 = ... | 1 | {
"code": "class Solution {\npublic:\n bool palindromic(std::string& str) {\n int size = str.size();\n int size2 = size / 2;\n for (int i = 0; i < size2; i++) {\n if (str[i] != str[size - (i + 1)]) {\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 = ... | 1 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int best_len = 0;\n string best_s = \"\";\n int n = s.length();\n for(int mid = 0; mid < n; mid++){\n for(int x = 0; mid - x >= 0 && mid + x < n; x++){\n if(s[mid-x] != s[mid+x]){\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 = ... | 1 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n if(s.length()<2){\n return s;\n }\n int maxlen =0;\n string result =\"\" ;\n int n = s.length();\n \n for(int i=0;i<n;i++){\n int left =i;\n int right =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 = ... | 2 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string& temp, size_t length)\n {\n for(int i = 0; i < length/2 + 1; ++i)\n {\n if(temp[i] != temp[length - i - 1])\n return false;\n }\n return true;\n }\n\n string longestPalindrome(string 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 = ... | 2 | {
"code": "class Solution {\npublic:\n std::string longestPalindrome(const std::string &s)\n {\n int n = s.length();\n if(n == 0) return \"\";\n int start = 0, max_length = 1;\n std::vector<std::vector<bool>> dp(n, std::vector<bool>(n, false));\n for(int i =0; i<n;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 = ... | 2 | {
"code": "bool palindromic_check(string s)\n{\n bool flag = true;\n \n for (int i = 0; i < s.size() / 2; i++)\n {\n if (s[i] != s[s.size() - 1 - i])\n {\n flag = false;\n break;\n }\n }\n \n return flag;\n}\n\nstring check_for_odd(string s)\n{\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int l = s.length();\n\n if(l <= 1) return s;\n\n string ans = \"\";\n ans += s[0];\n\n for(int i = 0; i < l; ++i) {\n string cur = \"\";\n for(int j = 1; i-j >= 0 && i+j < l; ++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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n int mx = 0;\n string ans;\n vector<vector<bool>> dp(n,vector<bool>(n,0));\n for(int i=0;i<n;i++){\n dp[i][i] = 1;\n for(int j=0;j<=i;j++){\n if(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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.length();\n vector<vector<bool>> matrix(n, vector<bool>(n, false));\n int maxlen = 0;\n string res;\n for (int i = n - 1; i >= 0; i--) {\n for (int j = i; j < n; 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size();\n\n string ans = \"\";\n int Mx = 0;\n for(int i = 0; i < n; i++){ \n // case 1 : odd length\n // choose current ele as middle\n int l = i-1;\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int ans = 1;\n pair<int,int> ans_ind= {0,0};\n stack<pair<int,int>> st;\n for (int i = 0; i<s.length(); i++){\n st.p... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n string ans = \"\";\n auto check = [&](int l, int r, string str)\n {\n string left,right;\n while(l >= 0 && r < s.size())\n {\n if(s[l] == s[r])\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 = ... | 2 | {
"code": "class Solution {\npublic:\n //Checks if index value is valid for string\n bool IsBoundsValid(string& string_to_check, int index_value)\n {\n return (index_value >= 0 && index_value <= string_to_check.length());\n }\n //Finds longest palindromic substring possible by expanding left and... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(const string &s) {\n string longest = \"\";\n int current_size = 0;\n int left = 0, right = 0;\n for (int i = 0; i < s.size(); ++i){\n left = i;\n right = i;\n checkPalingdrome(s, left, rig... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n bool checkPalindrome(string s, int start, int end){\n while(start < end){\n if(s[start] != s[end]) return false;\n start++;\n end--;\n }\n return true;\n }\n\n string longestPalindrome(string s) {\n int 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int sum=0;\n vector<pair<int,string>> vp;\n for(int i=0;i<s.length();i++){\n int l=i;\n int length=0;\n string d=\"\";\n for(int j=s.length()-1;j>=l;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 = ... | 2 | {
"code": "class Solution {\npublic:\n bool isPalindrome(string s) {\n int left = 0, right = s.length() - 1;\n while (left < right) {\n if (s[left] != s[right]) return false;\n left++;\n right--;\n }\n return true;\n }\n\n bool palindromeExist(stri... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n void setlongestPalindrome(string s, int index, int& maxCount, string& maxString){\n int count = 1;\n int prev = index - 1;\n int next = index + 1;\n while(prev>=0 && next<s.size()){\n if(s[prev] == s[next]){\n count += 2;\... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n string result;\n int get_len(int itr1,int itr2,string s)\n {\n int len=0;\n while(itr1>-1 and itr2<s.size())\n {\n if(s[itr1]==s[itr2])\n {\n len++;\n itr1--;\n itr2++;\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string result;\n int get_len(int itr1,int itr2,string s)\n {\n int len=0;\n while(itr1>-1 and itr2<s.size())\n {\n if(s[itr1]==s[itr2])\n {\n len++;\n itr1--;\n itr2++;\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string expand(int st, int dr, string s){\n string temp;\n while (st >= 1 && dr < s.length() - 1 && s[st - 1] == s[dr + 1]) {\n st--;\n dr++;\n }\n temp = s.substr(st, dr-st+1);\n return temp;\n }\n string longestP... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n int ans_start = 0, ans_end = 0;\n string longestPalindrome(string s) {\n ans_start = 0; ans_end = 0;\n int N = s.size();\n for (int mid = 0; mid < s.size(); mid++) {\n expand(s,mid, mid);\n if (mid + 1 < N && s[mid] == s[mid+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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n\n auto isPalindrome = [](string_view sv) {\n for (size_t i = 0; i < sv.size() / 2; ++i) {\n if (sv[i] != sv[sv.size() - i - 1]) {\n return false;\n }\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 = ... | 2 | {
"code": "class Solution {\npublic:\n int getPalindromFromMiddle(string s, int start, int end)\n {\n if (s == \"\" || start > end) \n return 0;\n auto size = s.length();\n \n while (start >= 0 && end < size && s[start] == s[end])\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 = ... | 2 | {
"code": "class Solution {\npublic:\n int expandAroundCenter(const string &s, int left, int right) {\n while (left >= 0 && right < s.length() && s[left] == s[right]) {\n left--;\n right++;\n }\n return right - left - 1;\n}\nbool isPalindrome(const string &s) {\n int l = 0, r = 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int res = 0;\n\n for (int i = 0; i < s.size(); i++) {\n res = max(res, lengthPalindrome(s, i).second);\n }\n for (int i = 0; i < s.size(); i++) {\n pair<int, int> length = lengthPalindrom... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n // vector<string> ans;\n\n bool isPalin(string s) {\n\n int n = s.size();\n int i = 0, j = n - 1;\n\n while (i <= j) {\n if (s[i] != s[j])\n return false;\n i++;\n j--;\n }\n\n return true;\... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n bool isPalin(int i,int j,string &s){\n if(i>=j) return true;\n if(dp[i][j]!=-1) return dp[i][j];\n\n bool ans=true;\n while(i<j){\n if(s[i]!=s[j]){\n ans=false;\n break;\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string spread(string s,int l,int r){\n while(l >= 0 && r < s.length() && s[l] == s[r]){\n l--;\n r++;\n }\n return s.substr(l+1,r-l-1);\n }\n string longestPalindrome(string s){\n string res;\n for(int i = 0;i < 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string spread(string s,int l,int r){\n while(l >= 0 && r < s.length() && s[l] == s[r]){\n l--;\n r++;\n }\n return s.substr(l+1,r-l-1);\n }\n string longestPalindrome(string s){\n string res;\n for(int i = 0;i < 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n=s.size();\n vector<vector<bool>>dp(n+1,vector<bool>(n+1,false));\n for(int i=0;i<=n;i++){\n dp[n][i]=true;\n dp[i][i]=true;\n }\n for(int i=n-2;i>=0;i--){\n for(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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n=s.size();\n vector<vector<bool>> dp(n, vector<bool> (n,0));\n string ans=\"\"; int cnt=0;\n for(int i=0;i<n;i++){dp[i][i]=1;}\n for(int i=n-2;i>=0;i--){\n string temp=\"\";\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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) \n {\n int longest=0,start=0;\n int explored=0;\n queue<pair<int,int>> q;\n q.push(make_pair(0,s.length()));\n while(!q.empty())\n {\n int left=q.front().first;\n int right=q... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n \n bool solve( int i ,string &p , int n){\n if(i>=n/2) return true;\n \n if(p[i] != p[n-i-1]) return false;\n return solve(i+1,p,n);\n }\n\n string solve(string &s){\n int n = s.size();\n int maxlen = INT_MIN;\n 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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n=s.size();\n string s1=s;\n reverse(s1.begin(),s1.end());\n if(s1==s)\n return s;\n vector<vector<int>> dp(n,vector<int>(n,0));\n int maxi=1;\n string ans=\"\";\n ans+=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 = ... | 2 | {
"code": "class Solution {\npublic:\n int isPalindrome(string& s, int i, int j, vector<vector<tuple<bool,bool>>>& cache) {\n if (i>j) return true;\n auto& [isSet, value] = cache[i][j];\n if (isSet) return value;\n\n if (s[i] == s[j]) {\n value = isPalindrome(s, i+1, j-1, cac... |
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 = ... | 2 | {
"code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n int n = s.size(), begin = 0, sz = 1;\n std::vector<std::vector<short>> dp(n, std::vector<short>(n, false));\n for (int i = 0; i < n; ++i) {\n dp[i][i] = true;\n }\n for (int i = n - 2; 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 = ... | 2 | {
"code": "class Solution {\npublic:\n int isPalindrome(string& s, int i, int j, vector<vector<tuple<bool,bool>>>& cache) {\n if (i>j) return true;\n if (i==j) return true;\n auto& [isSet, value] = cache[i][j];\n\n if (isSet) return value;\n\n if (s[i] == s[j]) {\n val... |
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 ml= -1;\n int mr = -1;\n int mlen = -1;\npublic:\n void getPalindromFromMiddle(string s, int start, int end)\n {\n if (s == \"\" ) \n return;\n int tmpr = start+end;\n int tmpl = start;\n while (tmpl >= 0 && tmp... |
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 maxi=0;\n string ans;\n void palin(string s, int i, int j)\n {\n\n while(i>=0 && j<s.length())\n {\n if(s[i]!=s[j])\n {\n if(j-i-1>maxi)\n {\n maxi=j-i-1;\n an... |
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() == 0) {\n return \"\";\n }\n int ls = 0;\n vector<int> res;\n for(int i = 0; i < s.size(); i ++) {\n vector<int> ind1 = find_palin(i, i, s);\n vector<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": "class Solution {\npublic:\n vector<int> expand(string s,int left,int right)\n {\n vector<int> indexes(2,-1);\n while(left>=0 && right<s.length())\n {\n if(s[left]==s[right])\n {\n indexes.clear();\n indexes.push_back(left);\n indexes.... |
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 extend(int a, int b, int N, string s){\n int i = 0; \n while(a-i >= 0 && b+i < N && s[a-i] == s[b+i]) i++; \n return i; \n }\n string longestPalindrome(string s) {\n string sm = \"#\";\n for(int i = 0; i < s.length(); 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 int extend(int a, int b, int N, string s){\n int i = 0; \n while(a-i >= 0 && b+i < N && s[a-i] == s[b+i]) i++; \n return i; \n }\n string longestPalindrome(string s) {\n string sm = \"#\";\n for(int i = 0; i < s.length(); 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 uint32_t startIndex = 0;\n uint32_t endIndex = 0;\n for (uint32_t i=0; i<s.size(); i++) {\n for (uint32_t j=i; j<s.size(); j++) {\n if (isPalindrome(s, i, j)) {\n const au... |
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 uint32_t startIndex = 0;\n uint32_t endIndex = 0;\n for (uint32_t i=0; i<s.size(); i++) {\n for (uint32_t j=i; j<s.size(); j++) {\n if (isPalindrome(s, i, j)) {\n const au... |
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 string math(int l, int r, string maxstr, string s){\n while(l >= 0 && r < s.size() && s[l] == s[r]){\n if((r - l + 1) > maxstr.size()){\n maxstr = s.substr(l, (r - l + 1));\n }\n l--;\n r++;\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 {\nprivate:\n string expandUntilPalindrome(string s, string max_str, int l, int r) {\n while (l >= 0 && r < s.size() && s[l] == s[r]) {\n if((r - l + 1) > max_str.size()) {\n max_str = s.substr(l, r - l + 1);\n }\n l -= 1;\n r += 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 string s1=s;\n reverse(s.begin(),s.end()); \n string ans;\n int n=s.size();\n int res=0;\n int dp[n+1][n+1];\n for(int i=0;i<=n;i++){\n for(int j=0;j<=n;j++){\n if(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 bool ispal(string a,int n){\n int s=0,e=n-1;\n while(e>s){\n if(a[s]!=a[e]){return false;}\n s++;e--;\n }\n return true;\n }\n string longestPalindrome(string s) {\n int n=s.length();\n string b=\"\";\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:\nbool isPalin(string s)\n{\n bool palin=true;\n int left=0;\n int right = s.size()-1;\n while(left<right)\n {\n if(s[left]!=s[right]){palin=false; break;}\n left++;right--;\n }\n return palin;\n}\n string longestPalindrome(string s)\n{\n int 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 string addPountSign(string s)\n {\n if (s.empty()) return \"#\";\n std::string res = \"#\";\n for (char c : s) {\n res += c;\n res += \"#\";\n }\n return res;\n }\n\n int calSizePalindrome(string s, int center)... |
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 pair<int,int> p={0,0};\n for(int i=0;i<s.size();i++){\n string a,b;\n for(int j=i;j<s.size();j++){\n a+=s[j];\n b.insert(b.begin(),s[j]);\n if(a==b && (j-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 maxLength = 0;\n string ans = \"\";\n for (int ptr = 0; ptr<s.size(); ptr++) {\n \n string reverse_str = \"\"; \n string check = \"\";\n\n for (int i = ptr; i < s.size(... |
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 length = s.length();\n\n if (length == 0)\n return \"\";\n\n int maxl = 1; // Length of the longest palindrome\n int start = 0; // Starting index of the longest palindrome\n\n // Allocate... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.