id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "class Solution {\npublic:\n vector<TreeNode*> generateTrees(int n) {\n // dp[i] stores all unique BSTs that can be formed with i nodes\n vector<vector<TreeNode*>> dp(n + 1);\n dp[0].push_back(nullptr); // Base case: One way to form BST with 0 nodes (empty tree)\n\n // Loop o... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "class Solution {\n public:\n TreeNode* clone(TreeNode* root){\n if(root == nullptr)\n return nullptr;\n TreeNode* newroot = new TreeNode(root->val);\n newroot->left = clone(root->left);\n newroot->right = clone(root->right);\n ... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "class Solution {\n public:\n TreeNode* clone(TreeNode* root){\n if(root == nullptr)\n return nullptr;\n TreeNode* newroot = new TreeNode(root->val);\n newroot->left = clone(root->left);\n newroot->right = clone(root->right);\n ... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "class Solution {\npublic:\n TreeNode * build(TreeNode * root){\n if(root==NULL){\n return NULL;\n }\n TreeNode * temp=new TreeNode (root->val);\n temp->left=build(root->left);\n temp->right=build(root->right);\n return temp;\n }\n vector<TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 2 | {
"code": "const static auto fast=[]{\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "class Solution {\npublic:\n\n vector<TreeNode*> generateTrees(int end, int start = 1) {\n vector<TreeNode*> ans; \n if ( start> end)\n return {nullptr};\\\n for (int i = start; i <= end; i++) {\n for (auto left : generateTrees(i - 1, start)) {\n ... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "class Solution {\n public:\n vector<TreeNode*> generateTrees(int n) {\n if (n == 0)\n return {};\n return generateTrees(1, n);\n }\n\n private:\n vector<TreeNode*> generateTrees(int... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "class Solution {\n public:\n vector<TreeNode*> generateTrees(int n) {\n if (n == 0)\n return {};\n return generateTrees(1, n);\n }\n\n private:\n vector<TreeNode*> generateTrees(int min, int max) {\n if (min > max)\n return {nullptr};\n\n vector<TreeNode*> ans;\n\n for (int i = ... |
95 | <p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST'</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><stron... | 3 | {
"code": "class Solution {\n public:\n vector<TreeNode*> generateTrees(int n) {\n if (n == 0)\n return {};\n return generateTrees(1, n);\n }\n\n private:\n vector<TreeNode*> generateTrees(int min, int max) {\n if (min > max)\n return {nullptr};\n\n vector<TreeNode*> ans;\n\n for (int i = ... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n if(n<=1) return 1;\n int ans=0;\n for(int i=1; i<=n; i++){\n ans+=numTrees(i-1) * numTrees(n-i);\n }\n return ans;\n }\n};",
"memory": "7100"
} |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n if(n<=1)\n return 1;\n int ans=0;\n for(int i=1;i<=n;i++)\n ans=ans+(numTrees(i-1)*(numTrees(n-i)));\n return ans;\n }\n};",
"memory": "7100"
} |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n if(n == 0){\n return 1;\n }\n if(n == 1 || n == 2){\n return n;\n }\n int ans = 0;\n for(int i = 1;i <= n;i++){\n ans += (numTrees(i-1) * numTrees(n-i));\n }\n ret... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n if(n <= 1){\n return 1;\n }\n int ans = 0;\n for(int i=1; i<=n; i++){\n ans = ans + numTrees(i-1)*numTrees(n-i);\n }\n return ans;\n }\n};",
"memory": "7200"
} |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n vector<int> dp(n+1,1);\n for(int node=2;node<=n;node++) {\n int cnt = 0;\n for(int i=1;i<=node;i++) {\n int left = dp[i-1];\n int right = dp[node-i];\n cnt += left*right;\... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n vector<int> dp(n + 1, 0);\n \n dp[0] = 1;\n \n for (int nodes = 1; nodes <= n; ++nodes) {\n for (int root = 1; root <= nodes; ++root) {\n dp[nodes] += dp[root - 1] * dp[nodes - root];\n ... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\nint solve(int n, vector<int>& dp){\n\nif(n<=1) return 1;\nif(dp[n]!=-1) return dp[n];\n int ans=0;\n for(int i=1; i<=n; i++){\n ans+=solve(i-1,dp) * solve(n-i,dp);\n }\n return dp[n]=ans;\n}\n int numTrees(int n) {\n vector<int> dp... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 0 | {
"code": "class Solution {\npublic:\n int solve(int n,vector<int> &dp){\n if(n == 0){\n return 1;\n }\n if(n == 1 || n == 2){\n return n;\n }\n if(dp[n] != 0){\n return dp[n];\n }\n int ans = 0;\n for(int i = 1;i <= n;i++){\n... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 1 | {
"code": "class Solution {\npublic:\n int numTrees(int n) {\n vector<int> sol(n+1,0);\n sol[0]=sol[1]=1;\n for(int i=2;i<=n;i++)\n {\n for(int j=1;j<=i;j++)\n {\n sol[i]+=sol[i-j]*sol[j-1];\n }\n }\n return sol[n];\n }\n}... |
96 | <p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST'</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<i... | 1 | {
"code": "class Solution {\n int solve(int n){\n vector<int> dp(n + 1,0);\n dp[0] = dp[1] = 1;\n\n for(int i = 2; i <= n;i++){\n for(int j = 1; j <= i;j++){\n dp[i] += dp[j - 1] * dp[i - j]; \n }\n }\n return dp[n];\n }\npublic:\n int n... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 0 | {
"code": "class Solution {\npublic:\n /*bool isInterleave(string& s1, string& s2, string& s3) {\n if(s3.length() != s1.length() + s2.length())\n return false;\n \n bool dp[s1.length()+1][s2.length()+1];\n dp[0][0] = true;\n for(int i=0; i<s1.length()+1; i++)\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 0 | {
"code": "#include <string>\n#include <vector>\n\nusing namespace std;\n\n// Using 1D Dynamic Programming: [O(m*n), O(n)]\nclass Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int m = s1.size();\n int n = s2.size();\n\n if (s3.size() != m + n) return false;\n\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n int m = s1.size();\n int n = s2.size();\n if (m + n != s3.size())\n return false;\n\n vector<vecto... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int m=s1.size();\n int n=s2.size();\n if(m+n!=s3.size())\n {\n return false;\n }\n\n vector<vector<int>> dp(m+1,vector<int> (n+1,0));\n\n for(int i=0;i<m+1;i++)\... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int m = s1.size(), n = s2.size();\n if (m + n != s3.size()) {\n return false;\n }\n vector<vector<int>> f(m + 1, vector<int>(n + 1, -1));\n function<bool(int, int)> dfs = [&](... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int m = s1.size(), n = s2.size();\n if (m + n != s3.size()) {\n return false;\n }\n vector<vector<int>> f(m + 1, vector<int>(n + 1, -1));\n function<bool(int, int)> dfs = [&](... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(const string& s1, const string& s2, const string& s3) { \n //return isInterleaveFullMem(s1, s2, s3);\n //return isInterleaveLinearMem(s1, s2, s3);\n return isInterleaveMemo(s1, s2, s3);\n }\n\n bool isInterleaveFullMem(string s1, s... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n struct Variant\n {\n int s1Pos{0};\n int s2Pos{0};\n };\n\n inline int generateHash(const Variant& variant)\n {\n return variant.s1Pos * 10000 + variant.s2Pos;\n }\n\n inline bool isVariantAccepted(const Variant& variant, const string& s... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n int arr[1001][1001];\nbool solve(string &s1,string& s2, string &s3, int i1, int i2, int i3, int l1, int l2, int l3)\n {\n if(i1==l1 && i2 == l2 && i3 == l3) \n return true;\n if(i3 == l3) \n return false;\n if(arr[i1][i2] != -1) ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\n map<pair<int,int>, int> dp1, dp2;\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n if (s1.size() + s2.size() != s3.size())\n return false;\n return isInterleave(s1, 0, s2, 0, s3, 0, true) || isInterleave(s2, 0, s1, 0, s3, 0, false);\n }\... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n if (s1.size() + s2.size() != s3.size()) {\n return false;\n }\n\n // d[i][j] := whether or not s1[:i + 1] and s2[:j + 1] can be interleaved \n map<pair<int, int>, bool> d;\n /... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n map<pair<int, int>, bool> cache;\n function<bool(int, int)> f = [&](const int i, const int j) {\n if ( (i == s1.length()) && (j == s2.length()) ) return true;\n if ( (s1[i] != s3[i+j]) ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool ok(int i,int j,int k,string &s1,string &s2,string &s3,vector<vector<int>> &dp)\n {\n if(i==s1.length() && j==s2.length() && k==s3.length())\n return true;\n \n bool x = false;\n bool y = false;\n if(dp[i][j]!=-1)\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n int m,n,N;\n int solve(int i,int j,string &s1,string &s2,string &s3,vector<vector<int>>&dp)\n {\n if(i==m && j==n && i+j==N)\n {\n return true;\n }\n if(i+j>=N || j>n || i>m)\n return false;\n if(dp[i][j]!=-1)\n return dp[i][j];\n int ta... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "map<pair<int,pair<int,int>>,int> mp;\nclass Solution {\npublic:\n string x=\"\",y=\"\",z=\"\";\n\n bool isInterleaving(int xInd, int yInd, int zInd){\n cout<<xInd<<\" \"<<yInd<<\" \"<<zInd<<endl;\n if(mp[{xInd,{yInd,zInd}}] == -1){\n cout<<\"Not Possible.\"<<endl;\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n std::vector<std::vector<int>> dp(101,std::vector<int>(101,-1));\n std::function<bool(int, int, int)> find;\n find = [&](int i1, int i2, int i3)->bool{\n if(dp[i1][i2] != -1){\n return dp[i1]... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n int m, n, N;\n int t[101][101][201];\n \n bool solve(int i, int j, int k, string& s1, string& s2, string& s3) {\n \n if(i == m && j == n && k == N) {\n return true;\n }\n \n if(k >= N) //other string didn't get consumed a... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n int m, n, N;\n int t[101][101][201];\n \n bool solve(int i, int j, int k, string& s1, string& s2, string& s3) {\n \n if(i == m && j == n && k == N) {\n return true;\n }\n \n if(k >= N) //other string didn't get consumed a... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "\nbool dp1(int **dp, string s1,string s2,string s3)\n{\n if(dp[s1.size()][s2.size()]!=-1)\n {\n return dp[s1.size()][s2.size()];\n }\n if(s1.size()==0 && s2.size()==0)\n {\n dp[0][0]=1;\n return true;\n }\n if(s1.size()!=0 && s2.size()==0)\n {\n if(s3[s3.... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "\nbool dp1(int **dp, string s1,string s2,string s3)\n{\n if(dp[s1.size()][s2.size()]!=-1)\n {\n return dp[s1.size()][s2.size()];\n }\n if(s1.size()==0 && s2.size()==0)\n {\n dp[0][0]=1;\n return true;\n }\n if(s1.size()!=0 && s2.size()==0)\n {\n if(s3[s3.... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n int solve(string &s1,string &s2,string s3,int i,int j,vector<vector<int>>&dp)\n {\n if(s3.size() == i+j)\n {\n return true;\n }\n if(dp[i][j]!=-1)\n {\n return dp[i][j];\n }\n bool x = false,y = false;\... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n\n bool a(string s1,string s2,string s3,int i,int j,vector<vector<int>> &ans)\n {\n if(s3==\"\")\n return true;\n\n if(i==s1.length())\n return s3==s2.substr(j);\n\n if(j==s2.length())\n return s3==s1.substr(i);\n\n if(ans[i]... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "int dp[101][101][200][2];\nclass Solution {\n int f(int i, int j, int k, bool flag, string &s1, string &s2, string &s3)\n {\n if (i == s1.size() && j == s2.size() && k == s3.size()) return 1;\n else if (j == s2.size() && i == s1.size()) return 0;\n else if (k == s3.size()) return... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool find(int i,int j,string &s1, string &s2, string &s3,string s, vector<vector<int>> &dp){\n if(i==s1.length() && j==s2.length() && s3==s) return true;\n if(dp[i][j]!=-1) return dp[i][j];\n string temp;\n bool a=false,b=false;\n if(i<s1.le... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\npublic:\n bool isInterleave(const string& s1, const string& s2, const string& s3) {\n\n const auto size1 = s1.size();\n const auto size2 = s2.size();\n const auto size3 = s3.size();\n if ((size1 + size2) != size3)\n {\n return false;\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 2 | {
"code": "class Solution {\n vector<vector<int>> dp;\n bool f(int i,int j,int k,string s1, string s2, string s3){\n if(k==s3.length()) return true;\n if(i==s1.length() and j==s2.length()) return false;\n if(dp[i][j]!=-1) return dp[i][j];\n if(s1[i]!=s3[k] and s2[j]!=s3[k]) ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution{\n\n vector<vector<int>> dp;\n\n\n bool recursion(string s1, string s2, string s3, int i,int j,int k){\n if(k >= s3.size())\n return true;\n\n\n if(dp[i][j] != -1) return dp[i][j];\n\n bool x = false;\n\n if(i < s1.size() && s1[i] == s3[k]){\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\n int table[101][101][201][2];\npublic:\n bool calc( string & s1, string &s2, string &s3, int i, int j, int k, bool process_s1){\n bool ans = false;\n\n if( i == s1.length() && j==s2.length() && k == s3.length() ){\n return true;\n }\n if(table[... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,bool>dp;\n bool isinter(string s1,string s2,string s3,int i,int j)\n {\n if(dp.find({i,j})!=dp.end()) return dp[{i,j}];\n if(i==s1.size()&&j==s2.size()) return true;\n if(s3[i+j]==s1[i]&&isinter(s1,s2,s3,i+1,j)) return dp[{i,j}]= t... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n set<pair<string,string>>key;\n bool dfs(string s1,string s2,string s3){\n if(s1.empty()&&s2.empty())return 1;\n if(key.find({s1,s2})!=key.end())return 0;\n if(!s1.empty()&&!s3.empty()&&s1[0]==s3[0]&&dfs(s1.substr(1),s2,s3.substr(1))){\n retu... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp;\n bool dfs(string s1, string s2, string s3 , int i , int j , string curr){\n cout<<curr<<endl;\n if(curr.size() == s3.size()){\n return (curr == s3);\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int, int>, bool> memo;\n bool backtrack(int i , int j, string s1, string s2, string s3) {\n if (i >= s1.size() && j >= s2.size()) {\n return true;\n }\n\n if (memo.count({i,j})) \n {\n return memo[{i,j}];\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\nprivate:\n map<vector<int>, bool> memo;\n\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n if (s1.size() + s2.size() != s3.size())\n return false;\n return helper(s1, s2, s3, 0, 0, 0);\n }\n bool helper(string s1, string s2, string s3,... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "int dp[1001][1001];\nclass Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int n = s1.length();\n int m = s2.length();\n int len = s3.length();\n\n if(n+m != len) return 0;\n dp[n][m];\n memset(dp,-1,sizeof(dp));\n return solv... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "#include <vector>\nclass Solution {\npublic:\n \n vector<vector<int>> dp; \n bool dfs(int i,int j,int k,string a,string b,string c){ \n bool ans = false; \n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) \n {\n vector<vector<int>> dp(s1.size() + 1 , vector<int>(s2.size() + 1 , -1));\n return Recursive(0,0,s1,s2,s3,dp,\"\");\n }\n\n bool Recursive(int i , int j , string s1 , string s2 , string s3, vecto... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\n unordered_map<int, unordered_map<int, unordered_map<int, bool>>> dp;\npublic:\n bool isInterleave(string s1, string s2, string s3, int i = 0, int j = 0, int k = 0) {\n int l1 = s1.length();\n int l2 = s2.length();\n int l = s3.length();\n if (i == l1 && ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n if (s2.size() < s1.size()) {\n std::string tmp = s1;\n s1 = s2;\n s2 = tmp;\n }\n \n if (s3.size() != s1.size() + s2.size()) return false;\n if(s3.size() == 0) return true;\n \n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n map<set<string>,bool> entry;\n bool isInterleave(string s1, string s2, string s3) {\n cout<<\"checkig for \"<<s1<<\" \"<<s2<<\" \"<<s3<<endl;\n set<string> s;\n s.insert(s1);\n s.insert(s2);\n if(entry.find(s)!=entry.end()){\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n int j=0,i=0;//j is pointer to s2 and i is to s1\n int n=0,m=0;//m is completed paritions of s1 and n is completed partitions of s2\n int prev =0;//indicates which string the last partition was in\n ... |
97 | <p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and... | 3 | {
"code": "class Solution {\npublic:\n int dp[101][101][201];\n bool check(string s1, string s2, string s3, int i, int j, int k){\n if(k==s3.length()) return true;\n if(dp[i][j][k]!=-1) return dp[i][j][k];\n bool ans = false;\n if(s1[i]==s2[j] && s1[i]==s3[k]){\n ans = ch... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.