id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool mylowestCommonAncestor(TreeNode*& root, TreeNode*& p, TreeNode*& q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool path(TreeNode * root, TreeNode * p, vector<int>&res){\n if(...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* ans=NULL;\n bool find(TreeNode* root, TreeNode* p, TreeNod...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* ans=NULL;\n bool find(TreeNode* root, TreeNode* p, TreeNod...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void solve(TreeNode* root, TreeNode* target, vector<int>& ans, vector<i...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void inorder(TreeNode* root, vector<int>& v) {\n if (root == NUL...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n\n //ITERATIVE vs. RECUSRIVE\n TreeNode* lowestCommonAncestor(TreeNod...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void dfs(vector<TreeNode*> &wektor, TreeNode* &p, bool &bol){\n ...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n\n void dfs(vector<TreeNode*> &wektor, TreeNode* &p, bool &bol){\n ...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n #include<unordered_map>\nclass Solution {\n typedef TreeNode* ptr ;\n typedef TreeNode node ;\n...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n #include<unordered_map>\nclass Solution {\n typedef TreeNode* ptr ;\n typedef TreeNode node ;\n...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n \n bool pathFromRootToNode(TreeNode* root, TreeNode* child, std::vec...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n\n void lowest(TreeNode* root, TreeNode* p, TreeNode* q, int &count, Tre...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool find(TreeNode* root, TreeNode* p, vector<TreeNode*>& ans) {\n ...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findAncestors(stack<TreeNode*>& ancestors, int target, TreeNode* c...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool check(TreeNode* root, TreeNode* p, TreeNode* q,bool& a ,bool& b){\...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\nvoid fillStacks(TreeNode* root, TreeNode* p, bool& found, stack<TreeNode*>&...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findAncestors(stack<TreeNode*>& ancestors, int target, TreeNode* c...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findAncestors(stack<TreeNode*>& ancestors, int target, TreeNode* c...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool helper(TreeNode* root,stack<TreeNode*>& st,int z){\n if(roo...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n\n void helper(map<TreeNode*, TreeNode*> &parent, TreeNode* root)\n {...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findPath(TreeNode* root, TreeNode* target, vector<TreeNode*> &path...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findPath(TreeNode* root, TreeNode* target, vector<TreeNode*> &path...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool pathtonode(vector<TreeNode*> &arr,TreeNode*root,TreeNode* p){\n ...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *q...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\n bool path(TreeNode* root, int x, vector< TreeNode*>& arr){\n if(root==NUL...
236
<p>Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <cod...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool getPath(TreeNode* root, TreeNode* n, vector<TreeNode*> &arr){\n ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n\n static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, val_str; getline(cin, str) && getline(cin, val_str); cout << '\\n') ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n \n static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\n...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n if(node->next){\n node->val=node->next->val;\n ListN...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n if(node == NULL &&node->next==NULL ){\n return;\n ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n node->val=node->next->val;\n ListNode* temp=node->next;\n ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n ListNode* temp = node;\n while(temp->next!=NULL){\n ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n node->val=node->next->val;\n node->next=node->next->next;\n...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n ListNode *temp=node->next;\n node->val=temp->val;\n ...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n node->val = node->next->val;\n node->next = node->next->nex...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
1
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n node->val = node->next->val;\n node->next = node->next->nex...
237
<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p> <p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first node of <code>head</code>.</p> <p>All the values of the linked list are <strong>unique</str...
1
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n void deleteNode(ListNode* node) {\n node->val = node->next->val;\n node->next = node->next->nex...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = []() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) { return c >= '0' &...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) {\n return c >= '...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = []() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) { return c >= '0' &...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) {\n return c >= '...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = []() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) { return c >= '0' &...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "auto init = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 'C';\n }();\n\nclass Solution {\n\npublic:\n\n std::vector<int> productExceptSelf(std::vector<int>& nums) {\n \n int mulNums = 1;\n static constexpr auto npos = sta...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int mulNums = 1;\n static constexpr auto npos = static_cast<size_t>(-1);\n auto posZero = npos;\n auto size = nums.size();\n\n for (size_t i = 0; i < size; ++i) {\n int num = nu...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int mulNums = 1;\n static constexpr auto npos = static_cast<size_t>(-1);\n auto posZero = npos;\n auto size = nums.size();\n\n for (size_t i = 0; i < size; ++i) {\n int num = nu...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int mulNums = 1;\n static constexpr auto npos = static_cast<size_t>(-1);\n auto posZero = npos;\n auto size = nums.size();\n\n for (size_t i = 0; i < size; ++i) {\n int num = nu...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int mulNums = 1;\n static constexpr int npos = -1;\n auto posZero = npos;\n int size = nums.size();\n\n for (int i = 0; i < size; ++i) {\n int num = nums[i];\n\n if (...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "auto init = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 'C';\n }();\n\nclass Solution {\n\npublic:\n\n std::vector<int> productExceptSelf(std::vector<int>& nums) {\n \n int mulNums = 1;\n static constexpr auto npos = sta...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "auto init = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 'C';\n }();\n\nclass Solution {\n\npublic:\n\n std::vector<int> productExceptSelf(std::vector<int>& nums) {\n \n int mulNums = 1;\n static constexpr auto npos = sta...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nauto init = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 'C';\n }();\n\nclass Solution {\n\npublic:\n\n std::vector<int> productExceptSelf(std::v...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "auto init = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 'C';\n }();\n\nclass Solution {\n\npublic:\n\n std::vector<int> productExceptSelf(std::vector<int>& nums) {\n \n int mulNums = 1;\n static constexpr auto npos = sta...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "//Without Using Extra space, TC & SC : O(N) & O(1)\nclass Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int>re(n);\n\n re[0] =1;\n\n for(int i = 1; i < n;i++){//left part \n re[i] = re[i-1]* nums[i-1];\n }\n\...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n // Initialize a vector to store the results and a variable to keep track of the product of elements to the right\n int product = 1;\n vector<int> output(nums.size()); // Create an output vector of the ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans(n);\n ans[0] = 1;\n\n for(int i=1;i<n;i++)\n {\n ans[i] = ans[i-1] * nums[i-1];\n }\n\n int prod = 1;\n for(int i = n...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> vec(n, 1); \n \n if (n == 1) {\n return vec;\n }\n \n int temp = 1; \n \n // left \n for (int i = 0; i < n...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n const int NUM_VALS{61};\n const int NUM_VALS_OFFSET{30};\n int num_counts[NUM_VALS]{0};\n int powers[NUM_VALS]{0};\n int sol_set[NUM_VALS]{0};\n int n = nums.size();\n vector...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int i;\n int product;\n const int n = nums.size();\n int result[n];\n \n std::fill_n(result, n, 1);\n\n product = 1;\n for (i = 0; i < n; i++) {\n result[i]...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int i;\n int product;\n const int n = nums.size();\n int result[n];\n \n std::fill_n(result, n, 1);\n\n product = 1;\n for (i = 0; i < n; i++) {\n result[i]...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> answer(nums.size());\n \n int suffix[nums.size()];\n\n answer[0] = 1;\n suffix[nums.size()-1] = 1;\n\n for(int i = 1; i < nums.size(); i++){\n answer[i] = num...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& a) {\n const int size = a.size();\n int l[size];\n l[0] = 1;\n for (int i = 1; i < size; ++i) {\n l[i] = l[i - 1] * a[i - 1];\n }\n for (int i = size - 2, r = 1; i >= 0; --i) {\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n\n int n = nums.size();\n vector<int> ans(n,0);\n int prefix[n];\n prefix[0] = nums[0];\n int suffix[n];\n suffix[n-1] = nums[n-1];\n for(int i=1;i<n;i++){\n prefix[...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n \n int n = nums.size();\n int pref[n + 5], suff[n + 5];\n\n pref[0] = nums[0];\n for (int i = 1; i < n; i++)\n pref[i] = nums[i] * pref[i - 1];\n \n suff[n - 1] = nums...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans(n, 1);\n vector<int> suffix(n, 1);\n\n for (int i = n - 2; i >= 0; i--) {\n suffix[i] = suffix[i + 1] * nums[i + 1];\n }\n\n for (i...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int>left(n, 1);\n vector<int>right(n, 1);\n for(int i = 1; i<n; i++ ){\n left[i]=nums[i-1]*left[i-1];\n }\n \n for(int i = n-2; i>=0;...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n \n int n = nums.size();\n \n int prepro[n], sufpro[n];\n \n prepro[0] = nums.at(0);\n sufpro[n-1] = nums.at(n-1);\n\n for(int i = 1; i<n; i++) prepro[i] = prepro[i-1]*...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
1
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> pre(n);\n vector<int> suf(n);\n // prefix product array\n int p = nums[0];\n pre[0] = 1;\n for(int i=1 ; i<n ; i++){\n pre[i] = ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> track(nums.size(), 1);\n vector<int> result(nums.size(), 1);\n int currProd = 1;\n for (int i = 0; i < nums.size(); ++i) {\n result[i] *= currProd;\n currProd *=...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n\n int n=nums.size();\n vector<int> prefix(n, 1);\n \n\n for(int i=1;i<n;i++){\n\n prefix[i]=prefix[i-1]*nums[i-1];\n }\n\n vector<int>ans(n);\n int factor=1;\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> pre(n);\n vector<int> suff(n);\n // vector<int> ans(n);\n //prefix product array\n int p =nums[0];\n pre[0] =1;\n for(int i ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int>left(n, 1);\n vector<int>right(n, 1);\n for(int i = 1; i<n; i++ ){\n left[i]=nums[i-1]*left[i-1];\n }\n \n for(int i = n-2; i>=0;...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n\n int n= nums.size();\n\n vector<int> leftProd(n), rightProd(n);\n\n leftProd[0]= 1, rightProd[n-1]= 1;\n\n for (int i=1; i<n; i++) {\n leftProd[i]= nums[i-1]*leftProd[i-1];\n }...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n //[2,3,4]\n //[2,6,24]\n //[24,12,4]\n //[12,8,6]\n\n //[1,2,6]\n //[12,4,1]\n\n vector<int> ans;\n int prefix = nums[0]; \n int postfix = nums[nums.size() - 1]...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> out;\n long long pro=1;\n for(int i=0;i<nums.size();i++){\n pro*=nums[i];\n out.push_back(pro);\n }\n pro=1;\n for(int i=nums.size()-1;i>0;i--){\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector <int> answer;\n int product = 1;\n for(int i = 0; i < nums.size(); i++){\n product *=nums[i] ;\n answer.push_back(product);\n }\n product = 1;\n for(int...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) \n {\n int prod=1;\n int total_zeros=0;\n vector<int> ans;\n for(auto it:nums)\n {\n //prod*=it;\n if(it==0)\n {\n total_zeros++;\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> ans;\n \n int zero = 0;\n int product = 1;\n for(auto x : nums){\n if(x == 0){\n zero = zero + 1;\n }else{\n product = product ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int zeroCount = 0;\n int product = 1;\n int productExceptZero = 1;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==0)\n {\n zeroCount++;\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> ans;\n int zero_index = -1;\n int product = 1;\n int moreThanOne = 0;\n for(int i = 0; i < nums.size(); ++i) {\n if(nums[i] == 0) {\n zero_index = i;\n...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector <int> answer;\n int product = 1;\n for(int i = 0; i < nums.size(); i++){\n product *=nums[i] ;\n answer.push_back(product);\n }\n product = 1;\n for(int...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n=nums.size();\n vector <int> pre(n,1);\n vector <int> suf(n,1);\n for(int i=1;i<n;i++)\n {\n pre[i]=nums[i-1]*pre[i-1];\n }\n for(int i=n-2;i>=0;i--)\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> pre(n),suf(n);\n pre[0]=nums[0];\n suf[n-1]=nums[n-1];\n for (int i=1;i<n;i++){\n pre[i] = pre[i-1]*nums[i];\n }\n for (int i=n-...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> pre(n);\n vector<int> suf(n);\n \n // Pre\n pre[0] = 1;\n int p=nums[0];\n for(int i=1 ; i<n ; i++){\n pre[i] = p;\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n=nums.size();\n vector<int>pre(n);\n vector<int>suf(n);\n pre[0]=nums[0];\n suf[n-1]=nums[n-1];\n for(int i=1;i<nums.size();i++){\n pre[i]=nums[i]*pre[i-1];\n ...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(n);\n vector<int> left(n);\n vector<int> right(n);\n int product=1;\n for(int i=0;i<n;i++){\n if(i==0){\n left[i]=1;\n...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int>result(n);\n vector<int>left(n);\n vector<int>right(n);\n left[0]=1;\n right[n-1]=1;\n for(int i =1;i<n;i++){\n left[i]=nums[i-1]*left[i-1];...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> leftToRight(n, 1);\n vector<int> rightToLeft(n, 1);\n for(int index = 1; index < n; index++)\n leftToRight[index] = leftToRight[index - 1] * nums[ind...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
2
{ "code": "class Solution {\n public:\n vector<int> productExceptSelf(vector<int>& nums) {\n const int n = nums.size();\n vector<int> ans(n); // Can also use `nums` as the ans array.\n vector<int> prefix(n, 1); // prefix product\n vector<int> suffix(n, 1); // suffix product\n\n for (int i = 1...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n if (nums.size() == 2) {\n return {nums[1], nums[0]};\n }\n\n vector<int> preffix(nums.size(), 0);\n vector<int> suffix(nums.size(), 0);\n\n long int total = 1;\n for (int...
238
<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p> <p>The product of any prefix or suffix of <code>nums</code> is <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> left (nums.size());\n vector<int> right (nums.size());\n\n std::partial_sum(nums.begin(), nums.end(), left.begin(), std::multiplies<>{});\n std::partial_sum(nums.rbegin(), nums.rend()...