id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string,int> mp;\n int n = strs.size(),m,i,k=0;\n string s;\n vector<vector<string>> v;\n for(i = 0 ; i < n ; i++){\n m = strs[i].length();\n s... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string,int> hash_tables;\n vector<vector<string>> result;\n string orde,orde2;\n vector<string> aux;\n for(int i = 0; i < strs.size(); i++){\n orde = str... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "\nclass Solution {\n public:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> m;\n for (int i = 0; i < strs.size(); ++i) {\n auto temp = strs[i];\n ranges::sort(temp);\n m[temp].push_back(strs[i]);\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "int speedup =[]{std::ios::sync_with_stdio(0);std::cin.tie(0);return 0;}();\n#define all(x) (x).begin(), (x).end()\n#define f first\n#define s second\n#define VPSS vector<pair<string, string>>\n#define VVS vector<vector<string>>\n#define VS vector<string>\nclass Solution {\npublic:\n vector<vector<string... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<string> sortedStrings;\n vector<vector<string>> result;\n\n // Sort each string and store the sorted strings\n for (int i = 0; i < strs.size(); i++) {\n string s = str... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<string> sortedStrings;\n vector<vector<string>> result;\n\n for (int i = 0; i < strs.size(); i++) {\n string s = strs[i];\n sort(s.begin(), s.end());\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<string, vector<string>> mp;\n\n int n = strs.size();\n for(int i=0;i<n;i++) {\n string x = strs[i];\n sort(x.begin(), x.end());\n mp[x].push_back(strs[i]);... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string,vector<int>> mp;\n for(int i=0;i<strs.size();i++){\n string s=strs[i];\n sort(s.begin(),s.end());\n mp[s].push_back(i);\n }\n vecto... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<string>temp = strs;\n unordered_map<string,vector<string>>m;\n vector<vector<string>>res;\n for(int i = 0; i < strs.size(); i++){\n sort(temp[i].begin(), temp[i].end()... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n\n bool is_anagram(string s1, string s2)\n {\n int n1 = s1.size();\n int n2 = s2.size();\n if(n1 != n2) return false;\n vector<int> arr(26,0);\n for(int i=0 ; i<n1 ; i++) arr[s1[i]-'a']++;\n for(int i=0; i<n2 ; i++) arr[s2[i]-'a']--... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> hash;\n\n for(int i = 0; i < strs.size(); ++i)\n {\n string sortString = strs[i];\n // string sort\n for(int j = 0; j < s... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mp;\n \n for(auto x: strs){\n string word = x;\n sort(word.begin(), word.end());\n mp[word].push_back(x);\n }\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> groups;\n for (string& s : strs) {\n string key = s;\n sort(key.begin(), key.end());\n groups[key].push_back(s);\n }\n\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<string,vector<string>>mp;\n vector<vector<string>>res;\n for(auto it:strs)\n {\n string temp=it;\n sort(it.begin(),it.end());\n mp[it].emplace_bac... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<string, vector<string>> s1;\n vector<vector<string>> result;\n for(string s:strs) {\n string org = s;\n sort(s.begin(),s.end());\n s1[s].push_back(org);\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) \n {\n std::vector<std::string> s = strs;\n std::vector<std::vector<std::string>> v;\n //std::vector<std::unordered_map<int, int>> um;\n\n std::unordered_map<std::string, std::vector<std... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<string, vector<string>> sorted;\n\n int n = strs.size();\n\n vector<string> strsTemp = strs;\n\n for (int i = 0 ; i < n ; i ++) {\n sort(strsTemp[i].begin(), strsTemp[i].... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n\n std::string getKey(const std::string& str) {\n std::string signature(26, 0);\n \n for(int i = 0; i < str.size(); i++) {\n auto ord = str[i] - 'a';\n signature[ord]++;\n }\n\n return signature;\n }\n\n vector<vec... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n\n // bool isAnagram(string s, string t) {\n // if(s.size()!=t.size()) {return false;}\n // unordered_map<char,int> mp;\n\n // for(auto c : s)\n // {\n // mp[c]++;\n // }\n\n // for(auto c : t)\n // { \n // ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> vs;\n if(strs.size()<=0)\n { vs.push_back({\"\"});\n return vs;\n }\n \n unordered_map<string,vector<string>> um;\n for(auto i:str... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mapping;\n for(string temp_string : strs){\n string original = temp_string;\n sort(temp_string.begin(), temp_string.end());\n if... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<array<int, 26>, vector<string>> mp;\n for (const string& str : strs) {\n array<int, 26> key = {};\n\n for (const char& c : str) {\n key[(int)c - int('a')] += ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<array<int, 26>, vector<string>> mp;\n for (const string& str : strs) {\n array<int, 26> key = {};\n\n for (const char& c : str) {\n key[(int)c - int('a')] += ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string,vector<string>> mp;\n vector<vector<string>> result;\n for(int i=0;i<strs.size();i++){\n int arr[26] = {0};\n for(int j=0;j<strs[i].length();j++){\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> output;\n unordered_map<string, vector<string>> umap;\n\n if (strs.empty()) {return output;}\n\n for (string str : strs)\n {\n vector<char> char... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& arr) {\n vector<vector<string>> ans;\n unordered_map<string,vector<string>> mp;\n for(string str : arr){\n string lexo = str;\n sort(lexo.begin(),lexo.end());\n if(mp.fi... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, unordered_set<int>> mp;\n for(int i = 0; i < strs.size(); ++i){\n string copy = strs[i];\n sort(copy.begin(), copy.end());\n mp[copy].insert(i);... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "/*\n anagram? same length, same freq of characters\n input range: lowercase alphabet (26 characters)\n\n vector<int> counts(26, 0)\n\n strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\n*/\n\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "/*\n anagram? same length, same freq of characters\n input range: lowercase alphabet (26 characters)\n\n vector<int> counts(26, 0)\n\n strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\n*/\n\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<vector<char>, vector<string>> umap;\n vector<vector<string>> res;\n for(string str: strs){\n vector<char> key(28,0);\n for(char c:str) key[c-97]++;\n umap[... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution\n{\npublic:\n\tvector<vector<string>> groupAnagrams(vector<string> &strs)\n\t{\n\t\tunordered_map<string, vector<string>> mp;\n\n\t\tfor (const string &s : strs)\n\t\t{\n\t\t\tstring key = getKey(s);\n\t\t\tmp[key].push_back(s);\n\t\t}\n\n\t\tvector<vector<string>> result;\n\t\tresult.reserv... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>>ans;\n\n unordered_map<string, vector<string>>mp;\n\n for(int i=0;i<strs.size();i++)\n {\n string curr = strs[i];\n string count=\"0000000000... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> result;\n unordered_map<string, vector<string>> groups;\n for(auto & s : strs){\n groups[strSort(s)].push_back(s);\n }\n\n for(auto &e: groups){... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n string getAnagram(string word) {\n int chars[26] = {0};\n for(int i = 0; i < word.length(); i++) {\n int ch = word[i] - 'a';\n chars[ch]++;\n }\n string hash = \"\";\n for(int i = 0; i < 26; i++) {\n hash += ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> ans;\n for (string& s : strs) {\n array<int, 26> count = {0};\n for (char c : s) {\n count[c - 'a']++;\n }\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> ans;\n for (string& s : strs) {\n array<int, 26> count = {0};\n for (char c : s) {\n count[c - 'a']++;\n }\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> ans;\n\n for (string& s : strs) {\n array<int, 26> count = {0};\n\n // Count frequency of each letter in the string\n for (char ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n if(strs.size() == 0) return {{}};\n unordered_map<string, vector<string>> umap;\n for(int i=0; i < strs.size(); i++){\n string word = strs[i];\n vector<int> freq(26,0);\n... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n string newfunc(string &str){\n int arr[26]={0};\n for(int i=0; i<str.length(); i++){\n int index=str[i]-'a';\n arr[index]++;\n } \n string aux=\"\";\n for(int i=0;i<26;i++){\n aux+=to_string(arr[i]);\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<vector<int>, vector<string>, VectorHash> mp;\n for(string& s: strs){\n vector<int> tmp(26,0);\n for(char& c: s) tmp[c-'a']++;\n mp[tmp].push_back(move(s... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mp;\n // encode each string and add to map \n for (int i = 0; i < strs.size(); i++) {\n vector<int> freq(26, 0);\n for (auto &c : st... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\n string countStrSort(const string& input)\n {\n vector<int> count(26, 0);\n for(char c: input)\n count[c - 'a'] += 1;\n string out{};\n for(int i = 0; i < 26; ++i)\n {\n char c = 'a' + i;\n out += string(count[i], c... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n\n std::unordered_map<std::string,std::vector<std::string>> map;\n\n for(const auto & str: strs)\n {\n std::array<int,26> count = {0};\n\n for(auto c:str)\n {\n... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> m;\n for (const auto& s : strs) {\n int counter[26] = {0};\n for (const char c : s) {\n const int d = c - 'a';\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n // unordered_map<string, vector<string>> res;\n\n // for(int i=0;i<strs.size();i++){\n // string temp = strs[i];\n // sort(temp.begin(), temp.end());\n // res[temp].p... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n // hash each string\n unordered_map<string, vector<string>> map;\n for (string s : strs) {\n vector<int> count(26, 0);\n for (char c : s) {\n count[c - 'a'... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<vector<int>, vector<string>> mp;\n vector<vector<string>> ans;\n for (int i = 0;i < strs.size();i++){\n vector<int> frq(26);\n for (int j = 0;j < strs[i].length();j++... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<vector<int>,vector<string>>mpp;\n for(auto word:strs){\n vector<int>temp(26,0);\n for(int i=0;i<word.size();i++){\n temp[word[i]-'a']++;\n }\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> umap;\n for (const string &i: strs) {\n int freq[26];\n memset(freq, 0, sizeof(freq));\n for (const char &c: i) {\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n // std::unordered_map<string, vector<string>> wordMap;\n\n // for(string word: strs){\n // string sortedWord = word;\n // std::sort(sortedWord.begin(), sortedWord.end());\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n std::vector<std::vector<std::string>> anagrams;\n std::vector<std::unordered_map<char, int>> freqs;\n\n for (auto const& str : strs) {\n std::unordered_map<char, int> strFreq;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "\nclass Solution {\npublic:\n string getSignature(const string& s) {\n vector<int> count(26, 0);\n for (char c : s) {\n count[c - 'a']++;\n }\n\n string word = \"\";\n for (int i = 0; i < 26; i++) {\n if (count[i] != 0) {\n word += ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "//\n// n vector<int> (26)\n//\n//\n//\n//\n//\n//\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> map;\n\n for (string s : strs) {\n vector<int> freq (26);\n\n for (char c : s) {\n freq[c - 'a']++;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> ans;\n unordered_map<string,vector<string>> map;\n for(int i=0;i<strs.size();i++){\n vector<int> v(26,0);\n for(auto it:strs[i])v[it-'a']++;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n\nclass Solution {\npublic:\n std::vector<std::vector<std::string>> groupAnagrams(std::vector<std::string>& strs) {\n std::unordered_map<std::string, std::vector<std::string>> anagramGroups;\n\n for (const std::string& str : s... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& tmp) {\n unordered_map<string,int>mp;\n vector<vector<string>>res;\n int idx = 0;\n for(int i=0;i<tmp.size();i++){\n // string strs = tmp[i];\n // sort(strs.begin(),strs.end... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> ans;\n unordered_map<string,int> map;\n int cur=0;\n for(auto s:strs){\n string m=mask(s);\n if(map.find(m)==map.end()){\n ma... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n string vectorToKey(const std::vector<int>& v) {\n string key;\n for (int i : v) {\n key += to_string(i) + '#';\n }\n return key;\n }\n\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, ve... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n int n = strs.size();\n \n unordered_map<string, vector<string>> mp;\n for(auto s : strs) {\n string key = \"\";\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mp;\n vector<vector<string>> ans;\n for (auto str : strs) { \n mp[generateKey(str)].push_back(str);\n }\n for (auto it... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<string, vector<string>> mp;\n vector<vector<string>> ans;\n for (auto str : strs) { \n mp[generateKey(str)].push_back(str);\n }\n for (auto itr = mp.beg... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n\n vector<vector<string>> ans;\n int n = strs.size();\n if(n == 0) return ans;\n unordered_map<string,vector<string>> m;\n vector<int> arr(26);\n for(int i=0 ; i<n ; i++)\n... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mp;\n vector<vector<string>> res;\n for (string s : strs) {\n array<int, 26> count = {0};\n for (char c : s) {\n coun... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> anagramMap;\n \n for (string s : strs) {\n vector<int> count(26, 0);\n for (char c : s) {\n count[c - 'a']++;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n if (strs.empty()) return {};\n\n unordered_map<string, vector<string>> ans;\n for ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> anagramMap;\n \n for (string s : strs) {\n vector<int> count(26, 0);\n for (char c : s) {\n count[c - 'a']++;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n std::map<string, vector<string>> map;\n\n for (auto str : strs) {\n vector<int> arr(26);\n for (auto c : str) {\n arr[c-'a']++;\n }\n\n stri... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<vector<int>, vector<string>> um;\n for(string str : strs){\n vector<int> alph(26,0);\n for(char c : str){\n alph[c - 97]++;\n }\n if(!um... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<vector<int>,vector<string>> mapStrs;\n for (auto i : strs){\n vector<int> c(26,0);\n for (auto j : i){\n ++c[j - 97];\n }\n mapStrs[c].p... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> mp;\n for(auto s: strs){\n string hashString = \"\";\n vector<int> freq(26, 0);\n for(auto c: s) freq[c-'a']++;\n fo... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n string vec2str(vector<int>&v){\n string res = \"\";\n for(auto k:v){\n if(res==\"\"){\n res = to_string(k);\n continue;\n }\n res+=\",\" + to_string(k);\n }\n return res;\n }\n ve... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n string getSig(string str){\n vector<int> r(26,0);\n for(auto s:str){\n r[s-'a']++;\n }\n string res;\n for(auto i:r){\n res += '#';\n res += to_string(i);\n }\n return res;\n }\n vector<ve... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "\n\nclass Solution {\npublic:\n string f(string& s){\n vector<int>v(26,0);\n for(char c: s){\n v[c-'a']++;\n }\n string ans=\"\";\n for(int i=0; i<26; i++){\n string tmp=\"\";\n ans += 'a'+i;\n ans += to_string(v[i]);\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector< vector<string> > res;\n vector<string> group;\n vector< unordered_map<char, int> > maps;\n unordered_map<char, int> map;\n vector<int> chosen(strs.size(), 0);\n in... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n\n map<vector<int>, vector<string>> mp;\n\n for (int i = 0; i < strs.size(); i++) {\n vector<int> freq(26, 0);\n for (int j = 0; j < strs[i].size(); j++) {\n freq[... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n\n vector<vector<string>> ans;\n unordered_map<string,vector<string>> m;\n int n = strs.size();\n\n for(int i=0 ; i<n ; i++)\n {\n vector<int> arr(26,0);\n f... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> ans;\n\n for(auto& s : strs){\n vector<int> count(26, 0);\n for (char c : s){\n count[c - 'a']++;\n }\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if(x==1 || x==0){\n return x;\n }\n if(n==0){\n return 1;\n }\n if(n==1){\n return x;\n }\n if(n<0){\n if(n==INT_MIN){\n n=INT_MAX;\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n double ans = 1.0;\n long nn = abs(n);\n while(nn){\n if(nn%2 == 0){\n x = x*x;\n nn = nn/2;\n }\n else{\n ans = ans * x;\n nn = ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n long long N = n;\n if (N < 0) {\n x = 1 / x;\n N = -N;\n }\n\n double result = 1.0;\n \n while (N > 0) {\n if (N % 2 == 1) {\n result *= x; \n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n \n if(n==0){\n return 1;\n }\n\n long long N = n;\n\n if(N<0){\n x = 1 / x;\n N = -1 * N;\n\n }\n return powHelp(x, N);\n \n }\n double powHelp (double x, long long N){\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if (n == 0) // what I thought is if the exponent is 0, return 1 because any number raised to 0 is 1\n return 1.0;\n long N = n;\n if (N < 0) { // If n is negative, we convert the problem to a positive exp.\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double solve(double x, long n){\n if(n==0) return 1;\n if(n<0) return solve(1/x,-n);\n if(n%2 == 0) return solve(x*x , n/2);\n return x * solve(x*x,(n-1)/2);\n }\n double myPow(double x, int n) {\n return solve(x, (long)n);\n }\n}... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if (n == 1)\n return x;\n else if (n == -1)\n return 1 / x;\n else if (n == 0)\n return 1;\n else if (n % 2 == 0) {\n double w = myPow(x, n / 2);\n return w * ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if(n==0) return (double)(1);\n if(n==1) return x;\n double ans = 1;\n long long nn = abs(n);\n while(nn>0){\n if(nn%2==0){\n x*=x;\n nn/=2;\n }\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n\n long long N = n;\n if(N == 0) {\n return 1;\n }\n\n if (N < 0) {\n x = 1 / x;\n N = -N;\n }\n\n if(n%2 == 0) {\n return myPow(x*x,N/2);\n } else {\... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 0 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if(x==1)\n return 1.0;\n double d = 1.0;\n long long k=n;\n if(k<0)k= -1 * k;\n while(k)\n {\n if(k%2 == 0)\n {\n x = x*x;\n k = k/2;\n ... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 1 | {
"code": "\n\n\n \nclass Solution {\n public:\n double myPow(double x, int n) {\n return binaryExp(x, static_cast<long>(n));\n }\n\n private:\n double binaryExp(double x, long n) {\n if (n == 0... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 1 | {
"code": "class Solution {\npublic:\n double findPower(double x, int n){\n if(n == 0)return 1;\n else if(n == 1)return x;\n\n double ans = findPower(x, n/2);\n if(n%2 == 0)return ans*ans;\n else return ans*ans*x;\n }\n double myPow(double x, int n) {\n int p = abs(n... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 2 | {
"code": "class Solution {\npublic:\n\n double mypowHelper(double x, long n) {\n // Base case: if the exponent is 0, the result is 1\n if (n == 0) {\n return 1;\n }\n\n // Recursive case: if the exponent is positive\n double half = mypowHelper(x, n / 2);\n if (... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 2 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n double ans=1.00;\n long long m=n;\n if(n<0)\n m= -1*m;\n while(m){\n if(m%2 ){\n ans= ans * x;\n m = m-1;\n }\n else{\n x= x*... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 3 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n double ans = 1.0 ;\n long long nn= n;\n if (nn<0){\n nn = -1 *nn ;\n }\n while (nn>0){\n if (nn %2 == 0 ){\n x = x *x;\n nn = nn/... |
50 | <p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> x = 2.00000, ... | 3 | {
"code": "class Solution {\npublic:\n double myPow(double x, int n) {\n if (n == INT_MIN) \n {\n return 1 / (pow(x, INT_MAX) * x);\n }\n if(n == 0) return 1;\n if(n < 0) return 1 / pow(x, -n);\n if(n % 2 == 0) return (pow(x, n/2) * pow(x, n/2)); \n else... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 0 | {
"code": "class Solution {\nprivate:\n bool isPoss(vector<string>&t , int row , int col,int n){\n int c = col ;\n int cl = col -1 ;\n int cr = col + 1 ;\n\n while(row >= 0){\n if(c >= 0 and c < n and t[row][c] == 'Q'){\n return false ;\n }\n ... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 0 | {
"code": "class Solution {\npublic:\n bool isSafe(int row, int col, vector<string>& board, int n){\n int duprow=row;\n int dupcol=col;\n while(row>=0 && col>=0){\n if(board[row][col]=='Q'){\n return false;\n }\n row--;\n col--;\n ... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 1 | {
"code": "class Solution {\nprivate:\n vector<vector<string>> result;\n void backtracking (int n, int row, vector<string>& chessboard) {\n if (row == n) {\n result.push_back(chessboard);\n return;\n }\n for (int col = 0; col < n; col++) {\n if (isvalid (row... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 1 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<string>> final_result;\r\n int N;\r\n\r\nbool CanPlaceQueen( vector<string> &board,int row , int col){\r\n //column check neeche se upr\r\n for( int i= row -1 ; i>=0;i--){\r\n if(board[i][col] == 'Q' ) return false;\r\n }\r\n\r\n // l... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 1 | {
"code": "class Solution {\npublic:\nvector<vector<string>> solveNQueens(int n) {\n int* q = (int*)malloc(sizeof(int) * n);\n for(int i=0; i<n; i++) q[i] = -1;\n int solutionsFound = 0;\n vector<vector<string>> result;\n\n int idx = 0;\n while (idx != -1) {\n whil... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 1 | {
"code": "class Solution {\n typedef vector<string> board;\n\n void solve(vector<board> &b, board &state, vector<bool> &row, vector<bool> &d1, vector<bool> &d2, int n, int t) {\n if(n == t) {\n cout << \"done\\n\";\n b.push_back(state);\n return;\n }\n\n fo... |
51 | <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p>
<p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <st... | 2 | {
"code": "class Solution {\npublic:\n//3 map to check if the queen is not place in those directions\nunordered_map<int,bool>rowCheck;\nunordered_map<int,bool>topDiagnol;\nunordered_map<int,bool>bottomDiagnol;\n \n bool isSafe(int row,int col,vector<vector<char>>&board){\n if(rowCheck[row]==true){\n //means... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.