id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\n int l... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 0 | {
"code": "\nclass Solution {\npublic:\n ListNode* reverseKGroup(ListNode* head, int k) {\n if(head == NULL) {\n return NULL;\n }\n ListNode* check = head;\n for (int i = 0; i < k; ++i) {\n if (!check) return head; \n check = check->next;\n }\n ... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int>&v,int k)\n {\n int n = v.size();\n for(int i = 0; i < n; i += k)\n {\n if(i + k <= n) // Only reverse if a full group of size k can be formed\n {\n reverse(v.begin() + i, v.begin() + i + k);\... |
25 | <p>Given the <code>head</code> of a linked list, reverse the nodes of the list <code>k</code> at a time, and return <em>the modified list</em>.</p>
<p><code>k</code> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <code>k</code> then left-ou... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(std::vector<int>& nums) {\n if (nums.empty()) return 0;\n \n int k = 1;\n \n for (int i = 1; i < nums.size(); ++i) {\n if (nums[i] != nums[i - 1]) {\n nums[k++] = nums[i];\n }\n }\n \n return k;\n}\n\n};",
... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int x=1;\n for(int i=1;i<nums.size();i++){\n if(nums[i]!=nums[i-1]){\n nums[x]=nums[i];\n x+=1;\n }\n }\n return(x);\n }\n};",
"memory": "21000"
} |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int n = nums.size();\n int j = 0;\n for(int i = 1; i<n; i++){\n if(nums[i]!=nums[j]){\n nums[j+1] = nums[i];\n j++;\n } \n } \n return j+1;\n }\n};",
"memo... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n if (nums.empty()) return 0;\n int j=1;\n for(int i=1; i<nums.size(); i++){\n if(nums[i] != nums[i-1]){\n nums[j]=nums[i];\n j++;\n }\n }\n return... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "# include <vector>\nclass Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int x = 0 ; \n while(x < nums.size() -1 )\n {\n if(nums[x] == nums[x + 1])\n {\n if(x + 1 == nums.size() - 1)nums.pop_back();\n else{\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n#include <vector>\n\nint removeDuplicates(std::vector<int>& nums) {\n if (nums.empty()) return 0;\n\n int n = 1;\n for (int i = 1; i < nums.size(); ++i) {\n if (nums[i] != nums[i - 1]) {\n nums[n++] = nums[i];\n }\n }\n return n;\n}\n\n};",... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n // 0, 1, 2, 2, 3, 3, 3, 4,\n int removeDuplicates(vector<int>& nums) {\n if(nums.size() < 2){\n return nums.size();\n }\n int i = 1;\n int j = 1;\n while(i < nums.size()){\n if(nums[i] == nums[i-1]){\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int insertIndex = 1 ;\n for (int i=1 ; i<nums.size() ; i++){\n if (nums[i-1] != nums[i]){\n nums[insertIndex] = nums[i];\n insertIndex++;\n }\n }\n retu... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 0 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n // int cnt = 1;\n // int n = nums.size();\n // int i=0, j=1;\n\n // while(j <= n-1) { \n // if(nums[i]==nums[j]) {\n // j++;\n // }\n // else {\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 1 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int i = 0, j = 0;\n while(i < nums.size() && j < nums.size()) {\n if(nums[i] == nums[j]) {\n ++j;\n }\n else {\n ++i;\n nums[i] = nums[j];\n... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 1 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int j = 1;\n for(int i = 1; i < nums.size(); i++){\n if(nums[i] != nums[i - 1]){\n nums[j] = nums[i];\n j++;\n }\n }\n return j;\n }\n};",
"memory"... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int i = 0, n = nums.size();\n for(int j = 1; j<n; j++){\n if(nums[i]!=nums[j]){\n i++;\n nums[i] = nums[j];\n }\n }\n return i+1;\n }\n};",
"memory... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int sz = nums.size();\n int unique = 1;\n for(int i=1; i<sz; i++) {\n if(nums[i]!=nums[unique-1]) {\n nums[unique] = nums[i];\n unique++;\n } \n }\n\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n vector<int> sorted;\n \n for (int i = 0; i < nums.size(); i++) {\n bool unique = true;\n for (auto o : sorted) {\n if (o == nums[i]) {\n unique = false;\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n\n vector<int> expectedNums = nums;\n\n\n for (int i = 0; i < expectedNums.size(); ++i) {\n int count = 0;\n for (int j = 0; j < nums.size(); ++j) {\n if (expectedNums[i] == nums[j]) {\n count++;\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n\n vector<int> expectedNums = nums;\n\n\n for (int i = 0; i < expectedNums.size(); ++i) {\n int count = 0;\n for (int j = 0; j < nums.size(); ++j) {\n if (expectedNums[i] == nums[j]) {\n count++;\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n auto it=unique(nums.begin(),nums.end());\n nums.erase(it,nums.end());\n int k=nums.size();\n \n \n return k;\n\n \n }\n};",
"memo... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n int i,n;\n int j=0;\n n=nums.size();\n sort(nums.begin(),nums.end());\n for(i=0;i<n-1;i++){\n if(nums[i]!=nums[i+1]){\n nums[j++]=nums[i];\n }\n }\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int ele= nums[0];\n int flag=1;\n vector <int> v;\n v.push_back(nums[0]);\n for(int i=1; i<nums.size(); i++ )\n {\n if(ele!= nums[i])\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n bool isExist[201];\n memset(isExist, false, 201);\n std::vector<int> reserve(nums.size());\n int count = 0;\n int value = 0;\n for (int i = 0; i < nums.size(); ++i){\n value = num... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n bool isExist[201];\n memset(isExist, false, 201);\n std::vector<int> reserve(nums.size());\n int count = 0;\n int value = 0;\n for (int i = 0; i < nums.size(); ++i){\n value = num... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n set<int> st(nums.begin(),nums.end());\n nums.clear();\n nums.assign(st.begin(),st.end());\n\n return st.size();\n }\n\n};",
"memory": "22000"
} |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n set<int>st;\n for(int i=0;i<nums.size();i++)\n {\n st.insert(nums[i]);\n }\n int index=0;\n for(auto it:st)\n {\n nums[index]=it;\n index++;\n }\n return... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n set<int>map;\n for(int i=0;i<nums.size();i++){\n map.insert(nums[i]);\n }\n int j=0;\n for(int x:map){\n\n nums[j++]=x; \n }\n int k=map.size();\n return k;\n ... |
26 | <p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong... | 3 | {
"code": "class Solution {\npublic:\n int removeDuplicates(vector<int>& nums) {\n set<int> st(nums.begin(),nums.end());\n nums.clear();\n nums.assign(st.begin(),st.end());\n\n return st.size();\n }\n\n};",
"memory": "22100"
} |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int index = 0;\n for(int i = 0; i< nums.size(); i++){\n if(nums[i] != val){\n nums[index] = nums[i];\n index++;\n }\n }\n return index;\n }\n};... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int count=0;\n for(int i=0; i<nums.size(); i++){\n if(nums[i] != val){\n nums[count] = nums[i];\n count++;\n }\n }\n return count;\n }\n};",
... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int k = 0;\n for(int i = 0; i< nums.size(); i++){\n if(nums[i] != val){\n nums[k] = nums[i];\n k++;\n }\n }\n return k;\n }\n};",
"memory": "... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int k = 0;\n int i = 0;\n while(i<nums.size())\n {\n if(nums[i] != val)\n {\n swap(nums[k], nums[i]);\n k++;\n }\n i++;\n ... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int k=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]!=val)\n {\n nums[k]=nums[i];\n k++;\n }\n }\n return k;\n }\n};",
... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int i = 0;\n int j = nums.size();\n while (i < j) {\n if (nums[i] != val) i++;\n else {\n while (--j > i && nums[j] == val);\n if (j != i) nums[i++] = nu... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int sum=0;\n vector<int>sol;\n for(int i=0;i<nums.size();i++){\n if(nums[i]!=val){\n sum+=1;\n sol.push_back(nums[i]);\n }\n }\n nums.clear... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int index = 0;\n for(int i = 0; i< nums.size(); i++){\n if(nums[i] != val){\n nums[index] = nums[i];\n index++;\n }\n }\n return index;\n }\n};... |
27 | <p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of e... | 0 | {
"code": "class Solution {\npublic:\n int removeElement(vector<int>& nums, int val) {\n int k = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] == val) {\n nums.erase(nums.begin() + i);\n i--;\n }\n else {\n k++... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(const std::string& haystack, const std::string& needle) {\n // Ищем подстроку needle в строке haystack\n auto it = std::search(haystack.begin(), haystack.end(),\n needle.begin(), needle.end());\n // Проверяем, найде... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n int end = (int)haystack.length() - (int)needle.length() + 1;\n for (int i = 0; i < end; ++i) {\n int index = 0;\n while (haystack[i + index] == needle[index]) {\n if (++index == ... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n int n = haystack.size();\n int m = needle.size();\n\n for(int i =0; i<n; i++){\n for (int j=0; j<m; j++){\n if(needle[j] != haystack[i+j]){\n break;\n ... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n int final, count=0;\n int len1=haystack.size();\n int len2=needle.size();\n for(int i=0;i<len1;i++){\n if(haystack[i]==needle[0]){\n \n for(int j=0;j<len2;j++){... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n for(int i=0;i<haystack.size();i++){\n int j;\n for( j =0;j<needle.size();j++){\n if(haystack[i+j]==needle[j]){\n continue;\n }\n else{\... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution{\npublic:\npublic:\n int strStr(std::string haystack, std::string needle){\n int found=haystack.find(needle);\n if (found!=std::string::npos){\n return found;\n }else{\n return -1;\n }\n }\n};",
"memory": "7700"
} |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n return haystack.find(needle);\n }\n};",
"memory": "7700"
} |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n auto it = search(haystack.begin(), haystack.end(), needle.begin(), needle.end());\n if (it == haystack.end())\n return -1;\n else\n return it - haystack.begin();\n }\n};",
"memory":... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 0 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n\n int index = 0;\n int ans=-1;\n bool f = true;\n for(int i=0;i<haystack.length();i++){\n if(haystack[i]==needle[index]){\n index++;\n if(f){\n ... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 1 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n string s=needle+\"$\"+haystack;\n int n=s.length();\n int l=0;\n int r=0;\n vector<int>z(n,0);\n for(int i=1;i<n;i++)\n {\n if(i<r)\n {\n z[i]=... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 1 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n \nint haystackLen = haystack.length();\n int needleLen = needle.length();\n\n // Edge case: Empty needle\n if (needleLen == 0) return 0;\n\n // Edge case: Needle longer than haystack\n if (haystackLen < ne... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "\nclass Solution {\nprivate:\n vector<int> getZ(string s){\n int n = s.size();\n vector<int> z(n);\n z[0]=0;\n int l=0, r=0;\n for(int i=1; i<n; i++){\n if(i>r){\n l=r=i;\n while(r<n && s[r-l]==s[r]){\n r++;\n... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n \n int n = haystack.length();\n int m = needle.length();\n \n for(int i = 0;i<n;i++){\n for(int j=0;j<m;j++){\n if(haystack[i+j] != needle[j]){\n bre... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n int len=needle.size();\n int len_hay=haystack.size();\n for(int i=0 ; i<=len_hay-len ; i++)\n {\n if(haystack.substr(i,len)==needle)\n return i;\n }\n return -1;\n ... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n if (haystack.length() < needle.length()) {\n return -1;\n }\n \n for (int i = 0; i <= haystack.length() - needle.length(); i++) {\n if (haystack.substr(i, needle.length()) == nee... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "class Solution {\nprivate:\n vector<int> getZ(string s){\n int n = s.size();\n vector<int> z(n);\n z[0]=0;\n int l=0, r=0;\n for(int i=1; i<n; i++){\n if(i>r){\n l=r=i;\n while(r<n && s[r-l]==s[r]){\n r++;\n ... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 2 | {
"code": "class Solution {\n public:\n int strStr(string haystack, string needle) {\n const int m = haystack.length();\n const int n = needle.length();\n\n for (int i = 0; i < m - n + 1; i++)\n if (haystack.substr(i, n) == needle)\n return i;\n\n return -1;\n }\n};",
"memory": "8200"
} |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 3 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n int n=needle.size();\n int h=haystack.size();\n if(n>h){return -1;}\n for(int i=0;i<=(h-n);i++){\n if(needle==haystack.substr(i,n)){\n return i;\n }\n }\... |
28 | <p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<stro... | 3 | {
"code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n if(haystack.length()<needle.length())\n return -1;\n for(int i=0;i<=haystack.length()-needle.length();i++)\n {\n if(haystack.substr(i,needle.length())==needle)\n return i;... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n if(dividend == divisor)return 1;\n bool sign = true;\n if(dividend >=0 && divisor <0) sign = false;\n if(dividend <0 && divisor >=0)sign = false;\n\n long n = abs(dividend);\n long d = abs(div... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n int divide(int dividend, int divisor) {\n bool sign = (dividend < 0) == (divisor < 0);\n long long n = abs((long long)dividend);\n long long d = abs((long long)divisor);\n\n long long quotient = 0;\n\... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n //divd=div*(q)+r\n bool isPositive=false;\n if((dividend>0 && divisor>0) || (dividend<0 && divisor<0)){\n isPositive=true;\n }\n if(dividend==divisor){\n return 1;\n }\n ... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "\nclass Solution {\npublic:\n int divide(int a, int b) {\n if (b == 1) {\n return a;\n }\n if (a == INT_MIN && b == -1) {\n return INT_MAX;\n }\n bool sign = (a > 0 && b > 0) || (a < 0 && b < 0);\n a = a > 0 ? -a : a;\n b = b > 0 ? -... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n int divide(int dividend, int divisor) {\n if (dividend == divisor) {\n return 1;\n }\n\n if (dividend == INT_MIN && divisor == -1) {\n return INT_MAX;\n }\n\n bool sign = ... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "\nclass Solution {\npublic:\n int divide(int dividend, int divisor) {\n // without using multiplication, division, and mod operator.\n if(dividend == 0) return 0;\n if(divisor == 1) return dividend;\n if(dividend == divisor) return 1;\n\n dividend = (dividend == -21474... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n if (dividend==divisor) return 1;\n int sign=1;\n long long ans=0;\n if ((dividend>0 && divisor<0) || (dividend<0 && divisor>0)) sign=-1;\n long long n=abs(dividend);\n long long d=abs(divisor)... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n \n if (divisor == 0) return INT_MAX; \n if (divisor == -1 && dividend == INT_MIN) return INT_MAX; \n \n \n long long pDividend = llabs((long long)dividend); \n long long pDivisor = llabs((long... |
29 | <p>Given two integers <code>dividend</code> and <code>divisor</code>, divide two integers <strong>without</strong> using multiplication, division, and mod operator.</p>
<p>The integer division should truncate toward zero, which means losing its fractional part. For example, <code>8.345</code> would be truncated to <co... | 0 | {
"code": "class Solution {\npublic:\n int divide(int x_orig, int y_orig) {\n \n uint32_t x = abs(x_orig);\n uint32_t y = abs(y_orig);\n\n bool isPositive = ((x_orig > 0 && y_orig >0) || (x_orig < 0 && y_orig < 0));\n\n uint32_t q = 0;\n int power = 31;\n\n if (x ==... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 0 | {
"code": "class Solution {\npublic:\n\n inline bool equal(auto s1, auto e1, auto s2) {\n while (s1 != e1) {\n if (*s1 != *s2) {\n return false;\n }\n ++s1;\n ++s2;\n }\n return true;\n }\n\n inline auto findAndMark(auto words_b,... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 0 | {
"code": "const long long base = 31;\nconst long long mod = 1e9+7;\n\nclass Solution {\n long long hash(string &s, int i, int j, long long base, long long mod) {\n long long ans = 0;\n \n for(int p = i; p <= j; p++) {\n ans += s[p]-'a';\n ans *= base;\n ans %=... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(0), cout.tie(0);\n \n int n = words[0].length(), ln = s.length();\n vector<int>m1(26, 0), m2(26, 0), ans;\n map<strin... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int k = words[0].size(), n = words.size(), m = s.size();\n int len = k * n;\n if (k > m || len > m) return {};\n unordered_map<string, pair<int, int>> tracker;\n for (string s : ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n vector<int> ans;\n unordered_map<string, int> mp;\n for(auto wrd:words){\n mp[wrd]+=1;\n }\n \n int wl=words[0].length();\n\n for(int i=0;i<wl;i++){\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n vector<int> ans;\n map<string, int> mp;\n for(auto wrd:words){\n mp[wrd]+=1;\n }\n \n int wl=words[0].length();\n\n for(int i=0;i<wl;i++){\n i... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int wordSize = words[0].size();\n int numWords = words.size();\n int subStrSize = wordSize * numWords;\n unordered_map<string, long> wordToFreq;\n if(s.size() < wordSize)\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n unordered_map<char, int> spectrum;\n for(const auto& w : words) {\n for(char c : w) {\n spectrum[c]++;\n }\n }\n unordered_map<string, int> ws;\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n\n #define pii pair <int, int>\n #define nd second\n #define st first\n\n struct node {\n node* nxt[26];\n int id, cnt; \n node() {\n for (int i = 0; i < 26; i ++)\n nxt[i] = NULL;\n id = -1;\n cnt =... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n\n #define pii pair <int, int>\n #define nd second\n #define st first\n // typedef pair<int, int> pii;\n // typedef second nd;\n // typedef first st;\n\n struct node {\n node* nxt[26];\n int id, cnt; \n node() {\n for (int i = ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n map <string,int> freq,cur;\n vector<int> result;\n for(auto i:words){\n freq[i]++;\n }\n cur = freq;\n int m = words[0].size();\n int n = words.size(); \... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n map <string,int> freq,cur;\n vector<int> result;\n for(auto i:words){\n freq[i]++;\n }\n cur = freq;\n int m = words[0].size();\n int n = words.size(); \... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string S, vector<string>& words) {\n int wlen = words[0].length(), count = words.size(), slen = S.length();\n if (wlen * count > slen) return {};\n\n vector<int> ans;\n unordered_map<string, int> hash1;\n for (strin... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n std::vector<int> findSubstring(std::string s, std::vector<std::string> &words) {\n std::vector<int> substring_indices;\n // within the sliding window of length (n * l), maintain unused_words\n //\n std::unordered_map<std::string, int> window_words; // window_words i... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> solve(string s, vector<string>& words, int idx) {\n vector<int> ans;\n int n = words.size();\n int m = words[0].length();\n if (s.length() < m*n) return ans;\n int tokens_in_mp = n;\n unordered_map<string,int> st,mp;\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int m = words.size(), n = words[0].size(), ls = s.size();\n\n vector<int> ans;\n\n for(int i=0; i<n&&i<=ls-m*n; ++i){\n unordered_map<string,int> cnt;\n\n for(int j=0; j<... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int word_size=words[0].size();\n int words_size=words.size();\n \n vector<int> ans;\n for(int x=0;x<word_size;x++){\n int i=x,j=x;\n map<string,int> mp;\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int word_size=words[0].size();\n int words_size=words.size();\n \n vector<int> ans;\n for(int x=0;x<word_size;x++){\n int i=x,j=x;\n map<string,int> mp;\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\n\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int m=s.size(),n=words.size(),len=words[0].size();\n\n vector<int> ans;\n\n unordered_map<string,int> dic;\n\n for(string word: words) dic[word]++;\n\n for(int i=0;i<len;i++){\... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\n vector<int> loc;\n string s;\n void kmp(const string &w,int l){\n string test = w + \"#\" + s;\n //lps Implemenation\n vector<int> lps(test.size());\n int i=0,j=i+1;\n while(j<test.size()){\n if(test[i]==test[j]){\n lp... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Trie\n{\n Trie *next[26];\n int idx;\n Trie()\n {\n int i;\n for (i = 0; i < 26; i++)\n next[i] = NULL;\n idx = -1;\n }\n};\n\nclass Solution\n{\n Trie *t = new Trie;\n int find(string s, int idx, ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Trie\n{\n Trie *next[26];\n int idx;\n Trie()\n {\n int i;\n for (i = 0; i < 26; i++)\n next[i] = NULL;\n idx = -1;\n }\n};\n\nclass Solution\n{\n Trie *t = new Trie;\n int find(string s, int idx, ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class TrieNode{\n public:\n int count;\n char val;\n TrieNode* children[26];\n bool end;\n int tmpCount;\n TrieNode(){\n val = '.';\n for(int i =0; i < 26; ++i) children[i] = nullptr;\n end = false;\n count = 0;\n tmpCount = 0;\n }\n TrieNode(ch... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n int j = words[0].size();\n int n = words.size();\n int len = j * n;\n\n vector<int> ans;\n\n for(int start = 0; start < j; start++) {\n vector<string> temp;\n ... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "const auto fastIO = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n\n inline bool equal(auto s1, auto e1, auto s2) {\n while (s1 != e1) {\n if (*s1 != *s2) {\n re... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "// const auto fastIO = []() {\n// std::ios::sync_with_stdio(false);\n// std::cin.tie(nullptr);\n// std::cout.tie(nullptr);\n// return 0;\n// }();\n\n\nclass Solution {\npublic:\n\n inline bool equal(auto s1, auto e1, auto s2) {\n while (s1 != e1) {\n if (*s1 != *s2) {\n... |
30 | <p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findSubstring(string s, vector<string>& words) {\n unordered_map<string, int> m;\n unordered_map<string, int> freq;\n vector<int> res;\n int n = words[0].size();\n for(int i=0; i<words.size(); i++){\n m[words[i]] = i +... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.