id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n unordered_set<int> s;\n int n=nums.size();\n int ans=0;\n int mask=0;\n for(int i=31;i>=0;i--){\n mask|=(1<<i);\n for(int j=0;j<n;j++){\n s.insert(mask & nums[j]);...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int max = 0, mask = 0;\n unordered_set<int> t;\n // search from left to right, find out for each bit is there \n // two numbers that has different value\n for (int i = 31; i >= 0; i--){\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "#include <array>\n#include <vector>\n\nusing std::array, std::vector;\n\nconst int MAX_BIT = 31;\n\nstruct Node {\n array<Node*, 2> children{};\n};\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n for (int num : nums) {\n std::cout << std::bitset<MAX_BIT + 1>...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\n struct TrieNode{\n int mini;\n TrieNode* next[2];\n\n TrieNode(){\n mini=INT_MAX;\n next[0]=next[1]=NULL;\n }\n };\n\n class Trie{\n TrieNode *root;\n\n public:\n Trie(){\n root=new TrieNode();\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Node{\npublic:\n Node* links[2];\n bool flag = 0;\n bool is_contain(int ind){\n return links[ind]!=NULL;\n }\n};\nclass Trie{\n Node* root;\npublic:\n Trie(){\n root = new Node();\n }\n void insert(int val){\n Node* tmp = root;\n for(int i=31;i>=0;i...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\n struct TrieNode{\n int mini;\n TrieNode* next[2];\n\n TrieNode(){\n mini=INT_MAX;\n next[0]=next[1]=NULL;\n }\n };\n\n class Trie{\n TrieNode *root;\n\n public:\n Trie(){\n root=new TrieNode();\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Node{\npublic:\n Node* links[2];\n bool flag = 0;\n bool is_contain(int ind){\n return links[ind]!=NULL;\n }\n};\nclass Trie{\n Node* root;\npublic:\n Trie(){\n root = new Node();\n }\n void insert(int val){\n Node* tmp = root;\n for(int i=31;i>=0;i...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Trie{\n public:\n Trie* child[2];\n bool is_leaf;\n\n Trie(){\n this->is_leaf=false;\n this->child[0]=NULL;\n this->child[1]=NULL;\n }\n};\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int n=nums.size...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Trie {\npublic:\n Trie* children[2];\n int number;\n bool is_num = false;\n void insert(int x) {\n auto cur = this;\n bitset<32> str(x);\n\n for(int i = 31; i >= 0; i--) {\n if ( !cur->children[!str[i]] ) cur->children[!str[i]] = new Trie();\n cu...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "#define ff first\n#define ss second\nstruct Node{\n Node* links[2]={NULL};\n bool flag=false;\n \n void put(int c, Node* nw){\n links[c]=nw;\n return;\n }\n \n Node* get(int c){\n return links[c];\n }\n \n bool isend(){\n return this->flag;\n }\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "#define ff first\n#define ss second\nstruct Node{\n Node* links[2]={NULL};\n bool flag=false;\n \n void put(int c, Node* nw){\n links[c]=nw;\n return;\n }\n \n Node* get(int c){\n return links[c];\n }\n \n bool isend(){\n return this->flag;\n }\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct Node {\n Node* links[2] = {nullptr};\n \n bool containsKey(char ch) {\n return links[ch - '0'] != nullptr;\n }\n \n void put(char ch, Node* node) {\n links[ch - '0'] = node;\n }\n \n Node* get(char ch) {\n return links[ch - '0'];\n }\n};\n\nclass Tr...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node\n{\n public:\n Node * links[2]={nullptr, nullptr};\n\n bool contain(int bit)\n {\n return (links[bit]!=NULL);\n\n }\n Node * get(int bit)\n {\n return links[bit];\n }\n void put(Node * node,int bit)\n {\n links[bit]=node;\n }\n};\n\nclass Sol...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node\n{\n public:\n Node * links[2]={nullptr, nullptr};\n\n bool contain(int bit)\n {\n return (links[bit]!=NULL);\n\n }\n Node * get(int bit)\n {\n return links[bit];\n }\n void put(Node * node,int bit)\n {\n links[bit]=node;\n }\n};\n\nclass Sol...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n struct TreeNode {\n int val;\n TreeNode* children[2];\n TreeNode(int a) {\n val = a;\n for(int i = 0; i < 2; i++) children[i] = nullptr;\n }\n };\n\n TreeNode* root;\n\n int findMaximumXOR(vector<int>& nums) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode {\npublic:\n TrieNode* ch[2];\n};\n\nclass Solution {\n int get_num_bits(int num) {\n int c = 0;\n for(int i=0; i<32; i++) {\n int bit = 1<<i;\n if(bit & num) c = i;\n }\n return c+1;\n }\n string convert_to_string(int num, int si...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Trie {\n struct trieNode {\n trieNode * children[2];\n };\n\n trieNode * getNode() {\n trieNode * newNode = new trieNode();\n for (int i = 0; i < 2; i++) {\n newNode->children[i] = NULL;\n }\n return newNode;\n }\n\n trieNode * root;\n\npub...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct Node {\n Node* children[2] = {nullptr, nullptr};\n};\n\nclass Solution {\npublic:\n Node* root = new Node();\n\n string binaryForm(int n) {\n return bitset<32>(n).to_string(); \n }\n\n int binaryToDecimal(const string &binary) {\n return stoi(binary, nullptr, 2);\n }\...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode {\n \n public:\n TrieNode**children;\n\n TrieNode(){\n children = new TrieNode*[2];\n children[0] = NULL;\n children[1] = NULL;\n }\n};\nclass Trie{\n\n public:\n TrieNode *root;\n\n Trie() {\n root = new TrieNode();\n }\n\n void inse...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node{\n public:\n Node *links[2];\n\n bool containsKey(int bit){\n return (links[bit]!=NULL);\n }\n\n void put(int bit, Node* node){\n links[bit] = new Node();\n }\n\n Node* get(int bit){\n return links[bit];\n }\n};\n\nclass Trie{\n private:\n Node*...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": " struct Node{\n Node* links[2];\n bool containskey(int bit){\n return (links[bit]!=NULL);\n }\n Node* get(int bit){\n return links[bit];\n }\n void put(int bit,Node* node){\n links[bit]=new Node();\n }\n \n };\n c...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n struct Vertex\n {\n int next[2];\n bool output = false;\n Vertex()\n {\n fill(begin(next),end(next),-1);\n }\n };\n vector <Vertex> trie;\n map <pair<int,int>,int> mp;\n void Trie() \n {\n trie.emplace_bac...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n struct Vertex\n {\n int next[2];\n bool output = false;\n Vertex()\n {\n fill(begin(next),end(next),-1);\n }\n };\n vector <Vertex> trie;\n void Trie() \n {\n trie.emplace_back();\n }\n void insert(stri...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n unordered_set<uint32_t> pr[32];\n for(int x_: nums) {\n uint32_t x = x_;\n for(int l=0; l<=31; l++) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\n public:\n int findMaximumXOR(vector<int>& nums) {\n const int maxNum = ranges::max(nums);\n if (maxNum == 0)\n return 0;\n const int maxBit = static_cast<int>(log2(maxNum));\n int ans = 0;\n int prefixMask = 0; // Grows like: 10000 -> 11000 -> ... -> 11111.\n\n /...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\nprivate:\n // for checking and setting jth bit in number n\n bool isset(int n, int j){return n&(1<<j);}\n void setbit(int& n, int j){n|=(1<<j);}\n\npublic:\n int findMaximumXOR(vector<int>& nums) {\n \n int n = nums.size();\n int xorTillNow = 0;\n v...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class TrieNode {\n public:\n TrieNode* one;\n TrieNode* zero;\n TrieNode() {\n one = NULL;\n zero = NULL;\n }\n };\n\n TrieNode *root;\n void insert(string &s) {\n TrieNode* cur = root;\n for (aut...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct Node{\n Node* child[2];\n int cnt;\n vector<int> wend;\n\n Node(){\n child[0] = NULL;\n child[1] = NULL;\n \n cnt = 0; \n }\n};\nclass Trie{\npublic:\n Node* root;\n\n Trie(){\n root = new Node;\n }\n\n void insert(int n, int ln){\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct TrieNode{\n TrieNode *children[2];\n bool flag;\n \n TrieNode () {\n children[0] = nullptr;\n children[1] = nullptr;\n flag = false;\n }\n};\n\nclass Solution {\npublic:\n void dfs(TrieNode *left, TrieNode *right, int currNum) {\n if (!left || !right) re...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class TrieNode {\n public:\n TrieNode* one;\n TrieNode* zero;\n TrieNode() {\n one = NULL;\n zero = NULL;\n }\n };\n\n TrieNode *root;\n void insert(string &s) {\n TrieNode* cur = root;\n for (aut...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n struct TreeNode {\n int val;\n TreeNode* children[2];\n TreeNode(int a) {\n val = a;\n for(int i = 0; i < 2; i++) children[i] = nullptr;\n }\n };\n\n TreeNode* root;\n\n int findMaximumXOR(vector<int>& nums) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\nusing ints=int;\nusing doublee=double;\nusing vi=vector<ints>;\nusing pi=pair<ints,ints>;\nusing vvi=vector<vector<ints>>;\nusing vpi=vector<pi>;\n#define endl \"\\n\"\n#define all(arr) arr.begin(),arr.end()\n\nstruct node{\n ints prefixCount,wordCou...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int max = 0, mask = 0;\n for (int i = 31; i >= 0; i--)\n {\n mask |= (1 << i);\n set<int> s;\n for (int num : nums)\n {\n s.insert(num & mask);\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n int max_xor(vector<int>&arr, int n) {\n int maxx = 0, mask = 0;\n\n set<int> se;\n\n for (int i = 30; i >= 0; i--) {\n mask |= (1 << i);\n\n for (int i = 0; i < n; ++i) {\n se.insert(arr[i] & mask);\n }\n\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int n=nums.size();\n\n set<int> st;\n int max_X=0,mask=0;\n for(int i=30;i>=0;i--){\n mask=(mask|(1<<i));\n for(int j=0;j<n;j++){\n st.insert(mask&nums[j]);\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "string decimal_to_binary(int n){\n bitset<32> num = n;\n string s = num.to_string();\n return s;\n}\n\nstruct Node{\n Node * links[2];\n bool contains(char ch){\n return links[ch-'0']!=NULL;\n }\n Node *get(char ch){\n return links[ch-'0'];\n }\n void put(char ch,No...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct trie{\n trie *one;\n trie *zero;\n\n trie()\n {\n one = NULL;\n zero = NULL;\n } \n};\n\ntrie *root;\n\nstring change(int i)\n{\n string res(32,'0');\n int j =0;\n while(i)\n {\n if(i & 1)\n {\n res[j] = 1;\n }\n j++;\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct TrieNode {\n bool exists;\n TrieNode *nodes[2];\n\n TrieNode() {\n exists = false;\n nodes[1] = nodes[0] = nullptr;\n }\n};\n\nvoid insert(TrieNode *root, int num) {\n vector<int> bits(32, 0);\n \n for (int i = 0; i < 32; i++) {\n int m = 1<<i;\n if (...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n struct Node\n {\n Node* next[2];\n\n Node() {\n next[0] = NULL;\n next[1] = NULL;\n }\n };\n\n struct Node* head;\n\n void insert(string x)\n {\n struct Node* cur = head;\n for(int i=0;i<x.size();i++)\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "std::string fromIntToBitString(uint32_t num)\n{\n std::string bits;\n for(int i=0; i<32; i++){\n bits.push_back('0' + ((num >> i) & 1));\n }\n\n std::reverse(bits.begin(), bits.end());\n return bits;\n}\n\n\nstruct BitPrefixNode {\n BitPrefixNode* zero_left;\n BitPrefixNode* one...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node{\n public:\n Node* links[2];\n Node(){\n links[0]=NULL;\n links[1]=NULL;\n }\n};\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n Node* root=new Node();\n for(auto x:nums){\n Node* curr=root;\n string s=\"\"...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "#include <bits/stdc++.h>\nstruct Node {\n Node* links[2] = {NULL};\n bool flag = false;\n int cw = 0;\n int cp = 0;\n};\nclass Trie {\n\npublic:\n Node* root;\n Trie() { root = new Node; }\n\n void insert(string word) {\n Node* node = root;\n for (char ch : word) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node {\n vector<Node*> link;\npublic:\n Node() {\n link = vector<Node*>(2, nullptr);\n }\n\n bool containKey(int bit) {\n return link[bit] != nullptr;\n }\n\n void putKey(int bit, Node* node) {\n link[bit] = node;\n }\n\n Node* getKey(int bit) {\n r...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Trie{\n vector<Trie*>val;\n public:\n Trie(){\n val.resize(2,NULL);\n }\n void insert(int num, Trie *root){\n Trie*temp = root;\n for(int i=0;i<31;++i){\n bool rem;\n if((1<<(30-i)) & num)rem = 1;\n else rem = 0;\n if(tem...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node {\npublic:\n vector<Node*> v;\n Node() : v(2, nullptr) {}\n};\n\nclass Trie {\n Node* root;\npublic:\n Trie() {\n root = new Node();\n }\n\n void insert(int num) {\n Node* curr = root;\n for ( int i = 31; i>=0; i--) {\n int temp = 1 << i;\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": " struct Node{\n Node* link[2];\n\n bool refExist(char ch){\n return link[ch-'0']!=nullptr;\n }\n\n void putNode(char ch){\n link[ch-'0'] = new Node();\n }\n\n Node* getNode(char ch){\n return link[ch-'0'];\n }\n };\n\n\...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct Node{\n Node *link[2];\n\n bool containKey(char ch){\n return link[ch-'0']!=NULL;\n }\n\n void put(char ch,Node *node){\n link[ch-'0']=node;\n }\n\n Node *get(char ch){\n return link[ch-'0'];\n }\n\n};\n\nclass Trie{\n\n public:\n\n Node *root;\n\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Node{\n public:\n Node* links[2];\n};\nclass Trie{\n public:\n Node* root;\n Trie(){\n root = new Node();\n }\n void insert(string word){\n int n = word.length();\n Node * curr = root;\n for(int i=0;i<n;i++){\n if(curr->links[word[i]-'0']==N...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class TrieNode {\n public:\n TrieNode* child[2];\n TrieNode() {\n child[0] = nullptr;\n child[1] = nullptr;\n }\n };\n\n class Trie {\n public:\n TrieNode* root;\n Trie() {\n root = new TrieNode()...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode{\n public:\n TrieNode* child[2];\n TrieNode() {\n child[0] = nullptr;\n child[1] = nullptr;\n }\n};\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n TrieNode *root = new TrieNode;\n TrieNode* curr = root;\n for(int i =...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct TrieNode {\n TrieNode* child[2];\n bool endFlag;\n char data;\n\n TrieNode(char ch){\n data = ch;\n for(int i=0; i<2; i++){\n child[i] = NULL;\n }\n endFlag = false;\n }\n};\n\nclass Solution {\nprivate:\n TrieNode* root = new TrieNode('0');\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode{\n public:\n bool isTerminal;\n char ch;\n TrieNode *children[2];\n\n TrieNode(char ch){\n this->ch=ch;\n isTerminal = false;\n for(int i=0;i<2;i++){\n children[i]=NULL;\n }\n }\n};\n\nclass Solution {\npublic:\n\n string getbinaryS...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\nstruct TrieNode{\n TrieNode* childNode[2];\n int nodeData;\n TrieNode(){\n nodeData=0;\n for(int i=0; i<2; i++){\n childNode[i]=NULL;\n }\n }\n};\n\nvoid insert(TrieNode* root, string s, int no){\n\n TrieNode* current...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode{\npublic:\n struct Trie{\n Trie* next[2] = {NULL};\n bool isEnd = false;\n };\n\n Trie* root;\n\n TrieNode(){\n root = new Trie();\n }\n\n void insert(string word){\n Trie* temp = root;\n\n for(auto &c : word){\n int i = c - '0'...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class TrieNode {\npublic:\n int val;\n TrieNode* child[2];\n bool isTerminal;\n TrieNode(int val) {\n this->val = val;\n child[0] = child[1] = NULL;\n isTerminal = false;\n }\n};\nclass Trie {\npublic:\n TrieNode* root;\n Trie() { root = new TrieNode(-1); }\n vo...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "string num_to_string(int num){\n string s;\n while(num){\n int bit=(num&1);\n if(bit==0) s.push_back('0');\n else s.push_back('1');\n num>>=1;\n }\n while(s.size()<31) s.push_back('0');\n reverse(s.begin(),s.end());\n return s;\n}\nstruct trie_node{\n trie_n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class Trie{\n public:\n int value;\n vector<Trie*> children;\n bool isTerminal;\n\n Trie(int v, bool it = false):children(2, nullptr){\n value = v; \n isTerminal = it; \n }\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class Trie{\n public:\n int value;\n vector<Trie*> children;\n bool isTerminal;\n\n Trie(int v, bool it = false):children(2, nullptr){\n value = v; \n isTerminal = it; \n }\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n class Trie{\n public:\n int value;\n vector<Trie*> children;\n bool isTerminal;\n\n Trie(int v, bool it = false):children(2, nullptr){\n value = v; \n isTerminal = it; \n }\n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "const int LM = 31; // for bit Trie\nclass TrieNode {\n public:\n int data;\n bool isEnd;\n int endCnt;\n int preCnt;\n int k;\n vector<TrieNode*> child;\n \n TrieNode(int val, int K){\n data = val;\n k = K;\n isEnd = 0;\n endCnt = preCnt = 0;\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Trie {\npublic:\n Trie* child[2];\n Trie() {\n for(int i = 0; i < 2; i++) {\n child[i] = NULL;\n }\n }\n};\n\nclass Solution {\npublic:\n Trie* root = new Trie();\n\n void insert(string s) {\n Trie* temp = root;\n for (auto ch : s) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "struct Node{\n Node *link[2];\n};\n\nclass Solution {\npublic:\n \n\n Node* root;\n void insert(vector<int>& num){\n Node *node = root;\n for(int i=0;i<32;i++){\n if(node->link[num[i]]==NULL){\n node->link[num[i]]=new Node();\n }\n n...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n ll m = nums.size();\n vector<ll> f;\n f.push_back(0);\n f.push_back(0);\n ll n = 0;\n vector<vector<ll> > trie;\n trie.push_back(f);\n for(ll i=0; i<m; i++)...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n vector<vector<int>> nxt;\n nxt.push_back(vector<int>(2));\n int N = 0;\n for (auto num: nums) {\n int node = 0;\n for(int i = 30; i >= 0; i--) {\n int digit = ((1ll<<i) ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
3
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int ans=0;\n int c=1;\n vector<vector<int>> node(1, vector<int> (2,-1));\n for(auto k: nums){\n int x=0;\n for(int i=31;i>=0;i--){\n if((k>>i)&1){\n i...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution \n{\nprivate:\n struct WordDigitPair\n {\n std::string_view word;\n int digit = 0;\n };\n\n // Sorted in order of unique letters and length.\n // This allows determine the count for each digit efficiently.\n // E.g. we can just count how many letters that make...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution \n{\nprivate:\n struct WordDigitPair\n {\n std::string_view word;\n int digit = 0;\n };\n\n // Sorted in order of unique letters and length\n const std::vector<WordDigitPair> s_wordDigitPairs = \n {\n {\"zero\", 0},\n {\"two\", 2},\n {\"si...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\n public:\n const string originalDigits(const string& s) {\n u_short count[10] {0};\n const uint sLen = s.size();\n for (uint i = 0; i < sLen; ++i) {\n switch (s[i]) {\n case 'z': ++count[0]; break;\n case 'w': ++count[2];...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\n public:\n const string originalDigits(const string& s) {\n int count[10] {0};\n const int sLen = s.size();\n for (int i = 0; i < sLen; ++i) {\n switch (s[i]) {\n case 'z': ++count[0]; break;\n case 'w': ++count[2]; break...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n string number[10] = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};\n std::vector<std::pair<char, int>> mappingTable ={{'x', 6}, {'g', 8}, {'w', 2}, {'z', 0}, {'s', 7}, {'v', 5}, {'f', 4}, {'o', 1}, {'h', 3}, {'i', 9}};...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "static constexpr pair<char, int> digChars[10] = {{'z', 0}, {'w', 2}, {'x', 6}, {'s', 7}, {'g', 8}, {'h', 3}, {'v', 5}, {'f', 4}, {'o', 1}, {'e', 9}};\n\nstatic string digWord[10] = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};\n\nclass Solution {\npub...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\n public:\n string originalDigits(string s) {\n string ans;\n vector<int> count(10);\n\n for (const char c : s) {\n if (c == 'z')\n ++count[0];\n if (c == 'o')\n ++count[1];\n if (c == 'w')\n ++count[2];\n if (c == 'h')\n ++count[3]...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n std::vector<std::pair<char, int>> compare= {{'x', 6}, {'z', 0}, {'g', 8}, {'w', 2}, {'s', 7}, {'h', 3}, {'v', 5}, {'f', 4}, {'o', 1}, {'e', 9} };\n string number[10] = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};\n ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n vector<int> counter(26);\n for (char c : s) ++counter[c - 'a'];\n vector<int> cnt(10);\n cnt[0] = counter['z' - 'a'];\n cnt[2] = counter['w' - 'a'];\n cnt[4] = counter['u' - 'a'];\n cnt[6] =...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\n public:\n string originalDigits(string s) {\n string ans;\n vector<int> count(10);\n\n for (const char c : s) {\n if (c == 'z')\n ++count[0];\n if (c == 'o')\n ++count[1];\n if (c == 'w')\n ++count[2];\n if (c == 'h')\n ++count[3]...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n vector<int> freq(26, 0);\n string ans = \"\";\n for(int i = 0;i< s.size();i++){\n freq[s[i] - 'a']++;\n }\n for(int i = 0 ;i<freq[25...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n // 1. Declare state variables\n int length = s.length();\n std::vector<int> charCount(256, 0);\n \n // 2. Update count of characters\n for (int i = 0; i < length; i++) {\n charCount[s[i]]...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n int nums[10];\n vector<int> freq(26);\n for(int i=0;i<s.size();i++){\n freq[s[i]-'a']+=1;\n }\n nums[0]=freq['z'-'a'];\n nums[2]=freq['w'-'a'];\n nums[4]=freq['u'-'a'];\n nums[5]=freq['f'-'a']-nums[4];...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
0
{ "code": "class Solution \n{\nprivate:\n struct WordDigitPair\n {\n std::string_view word;\n int digit = 0;\n };\n\n // Sorted in order of unique letters and length\n const std::vector<WordDigitPair> s_wordDigitPairs = \n {\n {\"zero\", 0},\n {\"two\", 2},\n {\"si...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
1
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n int count[26] = {}, resultCount[10] = {};\n for (char c : s)\n count[c - 'a']++;\n vector<tuple<char, char, string>> digits{\n {'0', 'z', \"zero\"}, {'2', 'w', \"two\"}, {'4', 'u', \"four\"},\n ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
1
{ "code": "class Solution {\npublic:\n string helper(int num, int freq){\n string res = \"\", tmp = to_string(num);\n for(int i=1;i<=freq;i++) res += tmp;\n return res;\n }\n string originalDigits(string s) {\n vector<int> hash(256, 0), num(10, 0);\n for(auto c : s) hash[(int)c]++;\n num[0]...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
1
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n vector<string> digitWords{\n \"zero\",\n \"one\",\n \"two\",\n \"three\",\n \"four\",\n \"five\",\n \"six\",\n \"seven\",\n \"eight\",...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
1
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n vector<int> freq(26, 0);\n for(char ch: s)\n freq[ch - 'a']++;\n \n vector<string> names = {\n \"zero\",\n \"one\",\n \"two\",\n \"three\",\n \"fo...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n unordered_map<int, string> digit_to_word = {\n {0, \"zero\"}, // z\n {2, \"two\"}, // w\n {4, \"four\"}, // u\n {6, \"six\"}, // x\n {8, \"eight\"},// g\n {3, \"thre...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "#include <string>\n#include <unordered_map>\n\nusing namespace std;\n\nclass Solution {\npublic:\n string originalDigits(string s) {\n // Hash map to store the frequency of each letter in the input string\n unordered_map<char, int> count;\n for (char c : s) {\n count[c]++...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "#include <string>\n#include <unordered_map>\n\nusing namespace std;\n\nclass Solution {\npublic:\n string originalDigits(string s) {\n // Hash map to store the frequency of each letter in the input string\n unordered_map<char, int> count;\n for (char c : s) {\n count[c]++...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n /*\n string getDigits(string d, char digit, unordered_map<char, int>& m) {\n string res;\n while(1) {\n for(auto& c: d) {\n if(m[c] == 0) {\n return res;\n }\n }\n for(auto& c: ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n map<char,int>m;\n vector<int>digits(10,0);\n\n for(char c:s){\n m[c]++;\n }\n\n digits[0]=m['z'];\n digits[2]=m['w'];\n digits[4]=m['u'];\n digits[6]=m['x'];\n digits...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n unordered_map<char,int> count;\n for(char c : s)\n count[c]++;\n\n vector<int> digit(10,0);\n digit[0] = count['z'];\n digit[2] = count['w'];\n digit[4] = count['u'];\n digit[6] = ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n unordered_map<char, int> count;\n string result;\n for (char c : s)\n count[c]++;\n vector<tuple<char, char, string>> digits{\n {'0', 'z', \"zero\"}, {'2', 'w', \"two\"}, {'4', 'u', \"fou...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
2
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n map<char,int>m;\n string ans;\n for(auto it:s) m[it]++;\n \n vector<int> digitCount(10, 0);\n \n \n digitCount[0] = m['z']; \n digitCount[2] = m['w']; \n digitCount[4] = m['u']; \n ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n//0: zero\n//1: one\n//2: two\n//3: three\n//4: four\n//5: five\n//6: six\n//7: seven\n//8: eight\n//9: nine\n string originalDigits(string s) {\n unordered_map<char, int> um;\n for(char c: s) um[c]++;\n vector<string> strs {\n \"zero\",//z\n ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "#include <stdio.h>\n#include <string.h>\nclass Solution {\npublic:\n string originalDigits(string s) {\n int Outputlist[10] = {0};\n string string_output;\n\n for (int i = 0; i< s.size(); i++)\n {\n if (s[i] == 'z') \n {\n Outputlist[0]++;...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n int n=s.size();\n vector<int> v(26,0);\n\n for(int i=0;i<n;i++){\n v[s[i]-'a']++;\n }\n\n vector<int> ans(10,0);\n\n ans[0]=v['z'-'a'];\n ans[2]=v['w'-'a'];\n ans[4]=v['u'-'...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n int n=s.size();\n vector<int> v(26,0);\n\n for(int i=0;i<n;i++){\n v[s[i]-'a']++;\n }\n\n vector<int> ans(10,0);\n\n ans[0]=v['z'-'a'];\n ans[2]=v['w'-'a'];\n ans[4]=v['u'-'...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n vector<int> count(26);\n\n for( char ch: s){\n count[ch-'a']++;\n }\n\n vector<int> nums(10);\n //unique cases\n nums[0]=count['z'-'a'];\n nums[2]=count['w'-'a'];\n nums[4]=...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n vector<string> words = {\"zero\",\"two\",\"four\",\"six\",\"eight\",\"one\",\"three\",\"five\",\"seven\",\"nine\"};\n vector<int> nums = {0,2,4,6,8,1,3,5,7,9};\n vector<int> distinct = {'z','w','u','x','g','o','r','f','...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution {\npublic:\n string originalDigits(string s) {\n unordered_map<char, int> chars;\n vector<int> result(10, 0);\n string resultString;\n for (auto ch : s) {\n chars[ch]++;\n }\n while (chars['z'] > 0) {\n chars['z']--;\n ...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution \n{\nprivate:\n struct WordDigitPair\n {\n std::string_view word;\n int digit = 0;\n };\n\n // Sorted in order of unique letters and length\n const std::vector<WordDigitPair> s_wordDigitPairs = \n {\n {\"zero\", 0},\n {\"two\", 2},\n {\"si...
423
<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> s = "owoztneoer" <strong>Output:</strong> "012...
3
{ "code": "class Solution \n{\nprivate:\n struct WordDigitPair\n {\n std::string_view word;\n int digit = 0;\n };\n\n // Sorted in order of unique letters and length\n const std::vector<WordDigitPair> s_wordDigitPairs = \n {\n {\"zero\", 0},\n {\"two\", 2},\n {\"si...