id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n\n bool static cmp(string a, string b){\n return a.length()<b.length();\n }\n\n string longestCommonPrefix(vector<string>& strs) {\n sort(strs.begin(),strs.end(),cmp);\n string ans = strs[0];\n for(int i=1;i<strs.size();i++){\n int ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string ans;\n int n=strs.size();\n int mini=INT_MAX;\n for(int i=0;i<n;i++){\n int k=strs[i].size();\n mini=min(mini,k);\n }\n for(int i=0;i<mini;i++){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n std::string st = strs[0], answer = \"\";\n int k = 0;\n for (int i = st.length(); i > 0; i--) {\n for (int j = 1; j < strs.size(); j++) {\n if (strs[j].find(st.substr(0, i)) ==... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string pre=\"\";\n bool common = true;\n int size = 0;\n while(common)\n { \n // cout<<strs[0]<<\" \";\n char letter;\n if (strs[0]==\"\")\n {... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string str = \"\";\n\n for (int i = 0; i < strs[0].length(); i++) {\n\n str += strs[0][i];\n for (int j = 1; j < strs.size(); j++) {\n\n if (strs[j].substr(0,i+1).find(str)... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string prefix = \"\";\n\n int mi = strs[0].length();\n\n for(int i=1;i<strs.size();i++){\n mi = min(mi, (int)strs[i].length());\n }\n \n\n for(int i=0;i<mi;i++){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string re = \"\";\n int len = 1;\n bool isEnd=false;\n for (int len = 1; len <= strs.at(0).size(); len++) {\n for (int i = 1; i < strs.size(); i++) {\n int pos=strs.at(i... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string pre=\"\";\n bool common = true;\n int size = 0;\n while(common)\n { \n // cout<<strs[0]<<\" \";\n char letter;\n if (strs[0]==\"\")\n {... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string pre=\"\";\n bool common = true;\n int size = 0;\n while(common)\n { \n // cout<<strs[0]<<\" \";\n char letter;\n if (strs[0]==\"\")\n {... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string dum=\"\";\n vector<string>v;\n int min=strs[0].size();\n for(int i=0;i<strs.size();i++){\n if(min>strs[i].size())\n min=strs[i].size();\n }\n for(i... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n for (const auto &str : strs) {\n if (str == \"\") {\n return \"\";\n }\n }\n char firstChar = strs[0][0];\n for (const auto &str : strs) {\n if (st... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n return lcp(strs, 0, strs.size()-1);\n }\n string CommonPrefixUtil(string str1, string str2){\n string result;\n int n1 = str1.length(), n2 = str2.length();\n\n for(int i=0,j=0; i<=n1-1 && j... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string CommonPrefix(string strs1, string strs2) {\n string ans = \"\";\n int i;\n for (i = 0; i < min(strs1.size(),strs2.size()); i++) {\n if (strs1[i] != strs2[i]) {\n break;\n }\n }\n ans = strs1.substr... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\n string merge(string s1, string s2){\n if(s1==\"\") return \"\";\n if(s2==\"\") return \"\";\n string s = \"\";\n for(int i = 0; i<min(s1.size(), s2.size()); i++){\n if(s1[i]==s2[i]) s+=s1[i];\n else break;\n }\n return s;... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string common(string a, string b) {\n string ans = \"\";\n int i = 0;\n while(i < a.size() && i< b.size()) {\n if (a[i] != b[i])break;\n ans += a[i];\n i++;\n }\n return ans;\n }\n\n string calculate(in... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "#include <unordered_map>\n#include <memory>\n\nstruct Trie\n{\n string value;\n unordered_map<string, std::shared_ptr<Trie>> children;\n Trie(string value) : value(value) { }\n\n std::shared_ptr<Trie> insert (string value)\n {\n auto node = children.find(value);\n if (node != c... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n /* \n //This finds the common series of alphabets between strings. But the question wants only prefix. so we need to remove first loop.\n string common = \"\"; \n string common_guess = \"\... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\nprivate:\n static bool comp(string & v1, string & v2){\n return v1.size() > v2.size();\n }\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n\n int s_size = strs.size();\n if (s_size == 0) return \"\";\n else if (s_size == 1) return strs[0... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n = strs.size();\n\n string minLenStr = strs[ 0 ];\n for( int i = 1; i < n; i++ ) {\n if( strs[ i ].size() < minLenStr.size() ) {\n minLenStr = strs[ i ];\n }\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n = strs.size();\n\n string minLenStr = strs[ 0 ];\n for( int i = 1; i < n; i++ ) {\n if( strs[ i ].size() < minLenStr.size() ) {\n minLenStr = strs[ i ];\n }\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string prefix=strs[0];\n string aux=\"\";\n for(int i=1;i<strs.size();i++){\n for(int j=0;j<prefix.length();j++){\n if(j<strs[i].length()){\n if(prefix[j]==s... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if(strs.size() == 1)\n return strs[0];\n\n string ans = strs[0];\n\n for (int i = 1; i < strs.size(); i++){\n string temp = \"\";\n\n for (int j = 0; j < min(strs[i].siz... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string commonPrefix = strs[0];\n for(int i=1;i<strs.size();i++){\n string data = strs[i];\n string finalPrefix;\n for(int j=0;j<data.size();j++){\n if(data[j]=... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n = strs.size();\n int ans = 0;\n string prefix = \"\";\n for(int length = 1; length < 200; length++) {\n bool flag = true;\n string substr = \"\";\n for(int ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string longest_CP = strs[0];\n for(auto s:strs){\n int i=0;\n string ans = \"\";\n while(i<s.size() && i<longest_CP.size() && longest_CP[i] == s[i]){\n ans = ans... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longest(string& str,string& str1){\n int i=0;\n int j = 0;\n string s = \"\";\n\n while(i<str.length() && j<str1.length()){\n if(str[i]==str1[j]){\n s = s + str[i];\n i++;\n j++;\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if(strs.size()==1)\n {\n return strs[0];\n }\n string s=\"\";\n string s1=strs[0];\n string s2=strs[1];\n int min_length=min(s1.length(),s2.length());\n for(int i=0;i<... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string findPrefixTwo(string a, string b){\n //using two pointer each on a and b\n int i =0; \n int j = 0;\n\n string ans = \"\";\n\n while(i<a.size() || j<b.size()){\n if(a[i] == b[j]){\n ans = ans+a[i];\n i++, j++;\n }\n\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string prefixx(string s1, string s2){\n string ans = \"\";\n int i = 0 ;\n int n1 = s1.size();\n int n2 = s2.size();\n\n //if(n1 == 0 || n2 == 0 ) return ans;\n\n while(i< min(n1,n2)){\n if(s1[i] == s2[i]){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string line1 = strs[0];\n int result = 1;\n int counter = 0;\n if(strs.size() == 1)\n return strs[0];\n for(int i = 1; i <= line1.size(); i++)\n {\n for(int j ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int k = strs[0].size();\n string current = \"\";\n string after = \"\";\n bool whoops = false;\n string ans = \"\";\n\n if(strs.size() ==1){\n return strs[0];\n }\... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string compareTwoWords(string maxPreNow, string word){\n string newPrefix = \"\";\n for(int i = 0; i < word.size(); i++){\n if(word[i] == maxPreNow[i]){\n newPrefix = newPrefix + word[i];\n } else break;\n }\n r... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n unordered_set<char> set;\n int k = strs[0].size();\n string current = \"\";\n string after = \"\";\n bool whoops = false;\n vector<string> vect;\n\n if(strs.size() ==1){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n unordered_set<char> set;\n int k = strs[0].size();\n string current = \"\";\n string after = \"\";\n bool whoops = false;\n vector<string> vect;\n\n if(strs.size() ==1){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n unordered_set<char> set;\n int k = strs[0].size();\n string current = \"\";\n string after = \"\";\n bool whoops = false;\n vector<string> vect;\n\n if(strs.size() ==1){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int k = strs[0].size();\n string current;\n string after;\n bool whoops = false;\n string ans = \"\";\n\n if(strs.size() ==1){\n return strs[0];\n }\n\n for... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int k = strs[0].size();\n string current;\n string after;\n bool whoops = false;\n string ans = \"\";\n\n if(strs.size() ==1){\n return strs[0];\n }\n\n for... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int r ;\n for ( r = 0 ; ; r ++ ){\n bool possible = true;\n if ( strs[0].size() <= r) break;\n char c = strs[0][r];\n for ( string s: strs) {\n if (r ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n unordered_set<char> set;\n int k = strs[0].size();\n string current = \"\";\n string after = \"\";\n bool whoops = false;\n vector<string> vect;\n string ans = \"\";\n\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string ans;\n int i = 0;\n while(true){\n char curr_ch = 0;\n for(auto str: strs){\n if(i >= str.size()){\n curr_ch = 0;\n brea... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n \n string ans;\n int i=0;\n while(true){\n char curr_ch = 0;\n for(auto str: strs){\n if(i>= str.size()) {\n curr_ch = 0;\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string res = \"\";\n\n for(int i = 0;i<strs[0].size();i++)\n {\n for(auto s:strs)\n {\n if (s[i]!= strs[0][i])\n {\n return res;\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 0 | {
"code": "#include <execution>\n\nconst size_t POOL_SIZE = std::pow(1024, 3) * 0.1; // 1 GB\nvoid* gPool = std::malloc(POOL_SIZE);\nvoid* gPoolPtr = gPool;\n\nvoid* operator new(size_t size) {\n // Определяем выравнивание\n const size_t alignment = alignof(std::max_align_t);\n\n // Определяем доступное коли... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 0 | {
"code": "class Solution {\npublic:\n void bubbleSort(vector<int>& nums) {\n int n = nums.size();\n for (int i = 0; i < n - 1; i++) {\n for (int j = 0; j < n - i - 1; j++) {\n if (nums[j] > nums[j + 1]) {\n swap(nums[j], nums[j + 1]);\n }\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n vector<pair<int, int>> new_pos{{0, 1}};\n new_pos.reserve(nums.size());\n for (int i = 1; i < nums.size(); i++) {\n if (nums[i] == nums[i - 1]) {\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 2 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> helper(vector<int>& nums, int start, int end, int target) {\n vector<pair<int, int>> pairs;\n while (start < end) {\n int sum = nums[start] + nums[end];\n if (sum < target) {\n start++;\n } e... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "\nclass Solution\n{\npublic:\n vector<vector<int>> threeSum(vector<int> &nums)\n {\n\n set<vector<int>> s;\n sort(nums.begin(), nums.end());\n vector<int> v;\n\n vector<vector<int>> vv;\n int size = nums.size();\n\n if (size < 3)\n return vv;\n\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size()-1;\n vector<vector<int>> res;\n set<vector<int>> s;\n sort(nums.begin(),nums.end());\n for (int i=0; i<n-1; i++){\n if (i>0 && nums[i]==nums[i-1]) continue;\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n // vector<vector<int>> ans;\n // set<vector<int>> s1;\n // for(int i=0;i<nums.size();i++)\n // {\n // for(int j=i+1;j<nums.size();j++)\n // {\n // for(int k=j+... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n // vector<vector<int>> ans;\n // set<vector<int>> s1;\n // for(int i=0;i<nums.size();i++)\n // {\n // for(int j=i+1;j<nums.size();j++)\n // {\n // for(int k=j+... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> twosum(vector<int>& nums, int start, int target){\n int tmp, l=start, r=nums.size()-1;\n vector<vector<int>> ans;\n while(l<r){\n tmp=nums[l]+nums[r];\n if(tmp>target)\n r--;\n else if(... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n void print(unordered_map<int, int> mp){\n for(pair<int, int> p : mp){\n cout << p.first << \" \" << p.second << endl;\n }\n }\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int> > ans;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n unordered_map<int, int> m;\n for (int i=0; i!=nums.size(); i++) m[-nums[i]]=i;\n vector<vector<int>> ans;\n unordered_set<long> n;\n for (int i=0; i... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> ans;\n sort(nums.begin(), nums.end());\n map<int, bool> done;\n map<vector<int>, bool> doneSub;\n for (int i = 0; i < nums.size(); i++) { \n if(done.fin... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, int> counts;\n set<vector<int>> ans;\n \n void twoSum(int target) {\n for (auto it = begin(counts); it != end(counts); ++it) {\n auto& [num, count] = *it;\n if (count == 0) { continue; }\n \n --cou... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> twoSum(vector<int>& v, int start, int end, int target) {\n vector<pair<int, int>>res;\n unordered_map<string, bool> mp;\n int left = start;\n int right = end;\n while (left < right) {\n int currentTarget = v... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> outside;\n int low = 0;\n map<int, int> mp;\n for (int i = 0; i < nums.size(); i++) {\n mp[nums[i]]++;\n }\n vector<int> v1={0,0,0};\n vector<ve... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<int> tmp;\n set<vector<int>> s;\n unordered_map<int, vector<int>> m;\n int j = 0;\n for(int i = 0; i < nums.size(); i++) {\n // we don't need to store more than 3 of the s... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> ans;\n sort(nums.begin(),nums.end());\n unordered_map<int,int> left,right;\n left[nums[0]]++;\n for(int i=2;i<nums.size();i++){\n right[nums[i]]++;\n }... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>>ans;\n vector<int>v(3);\n sort(nums.begin(),nums.end());\n map<vector<int>,bool>b;\n // cout<<nums[0];\n unordered_map<int,int>m;\n //check for \n for(int i=0;i<nums... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <set>\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n set<vector<int>> solution;\n for (int i = 0; i < nums.size() - 2; i++)\n {\n int j = i + 1;\n int k = nums.size() - 1;\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <set>\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n set<vector<int>> solution;\n for (int i = 0; i < nums.size() - 2; i++)\n {\n int j = i + 1;\n int k = nums.size() - 1;\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int i,j,k;\n set<vector<int>>st;\n int n=nums.size();\n sort(nums.begin(),nums.end());\n if(nums.front()>=0 && nums.back()<=0){\n return {{0,0,0}};\n }\n if(nums.fr... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n if(nums.back()<=0&&nums.front()>=0)return {{0,0,0}};\n if(nums.back()<0&&nums.front()<0) return {};\n if(nums.back()>0&&nums.front()>0) return {};\n\n int ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> output;\n map<int,int> mid; //required number\n unordered_map<long long,bool> end;\n unordered_map<int,int> exists; //number of occurences\n unordered_map<int,int> start... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n // num -> indexes\n unordered_map<int, vector<int>> indexes;\n sort(nums.begin(), nums.end());\n\n for (auto i = 0; i < nums.size(); ++i) {\n indexes[nums[i]].push_back(i);\n }\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution{\nprivate:\n void check_if_duplicate(int a, int b, int c, vector<vector<int>>& ans, unordered_map<string, int>& ans_map)\n {\n vector<int> vec = {a, b, c};\n sort(vec.begin(), vec.end());\n string s = to_string(vec[0]) + \"/\" + to_string(vec[1]) + \"/\" + to_strin... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n unordered_map<int,vector<int>>mp;\n int tmp=0;\n vector<vector<int>>ans;\n for(auto it:nums){\n mp[it].push_back(tmp);\n tmp++;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n void twoSum(vector<int>nums,int i,int j,int target,vector<vector<int>>&v){\n while(i<j){\n if(nums[i]+nums[j]<target) i++;\n else if(nums[i]+nums[j]>target) j--;\n else{\n v.push_back({nums[i],nums[j],-target});\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n void twoSum(vector<int>nums,int i,int j,int target,vector<vector<int>>&v){\n while(i<j){\n if(nums[i]+nums[j]<target) i++;\n else if(nums[i]+nums[j]>target) j--;\n else{\n v.push_back({nums[i],nums[j],-target});\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>vec;\nvector<int>v;\nvoid solve(int i, int j, int target, vector<int>nums){\n int val = nums[i-1];\n while(i<j){\n if(nums[i]+nums[j]+val < 0) i++;\n else if(nums[i]+nums[j]+val > 0) j--;\n else{\n v.push_back(val);\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>vec;\nvector<int>v;\nvoid solve(int i, int j, int target, vector<int>nums){\n int val = nums[i-1];\n while(i<j){\n if(nums[i]+nums[j] < target) i++;\n else if(nums[i]+nums[j] > target) j--;\n else{\n v.push_back(val);\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n\n vector<vector<int>> res;\n\n sort(nums.begin(), nums.end());\n int n= nums.size();\n int prev = INT_MIN ;\n unordered_map<string,int> mp; \n for(int i=0; i<n; i++){\n if... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n\n vector<vector<int>> res;\n\n sort(nums.begin(), nums.end());\n int n= nums.size();\n int prev = INT_MIN ;\n unordered_map<string,int> mp; \n for(int i=0; i<n; i++){\n if... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <unordered_map>\n#include <vector>\n#include <set>\n#include <climits>\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n // Key: Number, value: vector of indexes of the number\n unordered_map<int, vector<int>> umap;\n // Set of sets (triplet... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <unordered_map>\n#include <vector>\n#include <set>\n#include <climits>\n\nclass Solution {\npublic:\n void sort(vector<int>& arr) {\n for (int i = 0; i < arr.size() - 1; i++) {\n int minIndex = i;\n for (int j = i + 1; j < arr.size(); j++) {\n if (arr... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& vec) {\n \n // sort(vec.begin(),vec.end());\n set<int>s;\n unordered_map<int,int>mp;\n vector<int>temp;\n set<multiset<int>> ans;\n vector<vector<int>> ansf;\n for(auto xy:vec)\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<vector<int>> ans;\n set <vector<int>> triplets;\n int n = nums.size();\n unordered_map <int, int> freq;\n for(int i = 0;i<n;i++)\n {\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>twoSum(int target, int low, vector<int>nums){\n vector<vector<int>>arr;\n int high = nums.size()-1;\n while(low<high){\n int sum = nums[low]+nums[high];\n if(sum==target){\n arr.push_back({low, high}... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\nprivate:\n vector<int> nums;\n\n vector<vector<int>> twoSum(int begin, int end, int target, vector<int> nums) {\n int left = begin;\n int right = end;\n int base = nums[left] + nums[right];\n vector<vector<int>> sol_set;\n\n while (left < right) {\... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> threeSum(vector<int>& nums) {\n \n unordered_map<int, int> map;\n vector<vector<int>> res;\n set<vector<int>> mySet;\n sort(nums.begin(), nums.end());\n\n if(nums[0] == nums[nums.size() - 1] && nums[0] == 0){\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n multimap<int,int> m;\n set<vector<int>> s ;\n vector<vector<int>> v ;\n sort(nums.begin(),nums.end());\n for(int i = 0; i<nums.size();i++)\n {\n if(m.count(nums[i])<=3)\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> result{};\n sort(nums.begin(), nums.end());\n\n for (int i = 0; i+2 < nums.size(); ++i) {\n if (nums[i] > 0) {\n break;\n }\n int kpr... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "const int OFFSET = 1e5;\n\nclass Solution {\npublic:\n int cnt[200001];\n void add(int val) {\n ++cnt[val + OFFSET];\n }\n void remove(int val) {\n --cnt[val + OFFSET];\n }\n\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(begin(nums), end(nums));\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> st;\n sort(nums.begin(),nums.end());\n //If even after sorting there is no -ve number then 0 sum cant be made\n if(nums[0]>0) return {};\n\n int n=nums.size();\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "//first come to twoSum\n\nclass Solution {\npublic:\n\n vector<vector<int>> threeSum(vector<int>& n) \n {\n auto print = [&]()\n {\n for(auto nn : n)\n cout << nn << \" \";\n cout << endl;\n };\n\n std::sort(n.begin(), n.end());\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <set>\nusing namespace std;\nclass Solution {\npublic:\n int binarySearch(int toFind, vector<int>& nums, int start){\n if(start < 0){\n start = 0;\n }\n\n int end = nums.size() - 1;\n while(start <= end){\n int index = start + (end - start) / 2;... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int>temp(3);\n vector<vector<int>>ans;\n int pos=-1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>=0){\n pos=i;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n set<vector<int>>st;\n for(int i=0;i<n-2;i++)\n {\n int k=i+1,j=n-1;\n while(k<j)\n {\n i... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n set<vector<int>>s;\n sort(nums.begin(),nums.end());\n for(int i=0;i<n-2;i++){\n if(i>0 && nums[i]==nums[i-1])i++;\n int j=i+1,k=n-1;\n while... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n set<vector<int>> req;\n vector<vector<int>> ans;\n for(int x = 0;x<n;x++)\n {\n if(x != 0 && nums[x] == nums[x-1])\... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<int> s;vector<vector<int>> ans;\n for(auto it : nums){\n s.insert(it);\n }\n if(s.size()==1 && nums[0]==0){\n vector<int> v;\n v={0,0,0};\n ans.push_back(v);\n return... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n unordered_map<int,vector<int>> targets;\n for (int i = 0; i < nums.size(); i++) {\n targets[nums[i]].push_back(i);\n }\n\n vector<vector<int>> result;\n int last_ni = INT32_MIN;\... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution \n{\npublic:\n vector<vector<int>> GetTwoSum(vector<int> v, int index)\n {\n int t = 0 - (v[index]);\n int front = index + 1;\n int back = v.size() - 1;\n vector<vector<int>> res;\n while (front < back)\n {\n if (v[front] + v[back] =... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution \n{\npublic:\n vector<vector<int>> GetTwoSum(vector<int> v, int index)\n {\n int t = 0 - (v[index]);\n int front = index + 1;\n int back = v.size() - 1;\n vector<vector<int>> res;\n while (front < back)\n {\n if (v[front] + v[back] =... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n unordered_map<int,vector<int> > present;\n // map<vector<int>,int> check;\n\n vector<vector<int>> threeSum(vector<int>& nums) \n {\n int n = nums.size();\n\n bool check=true;\n\n for(int x:nums)\n {\n if(x!=0){check=false; bre... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int len = nums.size();\n sort(nums.begin(),nums.end());\n int j,k;\n set<vector<int>> ans;\n for(int i=0;i<len-2;i++){\n if(nums[i]==nums[i+2]){\n if(nums[i]==0){\... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> res;\n set<vector<int>> seen;\n\n sort(nums.begin(), nums.end());\n\n for (int i = 0; i < nums.size() - 2; i++){\n int left = i + 1;\n int right = nums.si... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findTwoSum(vector<int>& nums, int l, int r, int sum) {\n vector<vector<int>> res;\n while (l < r) {\n int temp = nums[l] + nums[r];\n if (temp == sum) {\n res.push_back({sum * -1, nums[l++], nums[r--]});\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> threeSum(vector<int>& nums) {\n\n vector<vector<int> > fin;\n set<vector<int> > res;\n if(nums.size()<3)\n return fin;\n\n sort(nums.begin(), nums.end());\n int p=0;\n int q=1;\n int r=nums.size()-1;\n\n\n int posl=r;\n\n whil... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.