Skip to content

Commit

Permalink
Start LeetCode January Challenge:
Browse files Browse the repository at this point in the history
Add problems 1 and 2.
  • Loading branch information
pin3da committed Jan 2, 2021
1 parent 8a535f4 commit ddcf7fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
29 changes: 29 additions & 0 deletions solved/LeetCode/Challenges/2020/January/01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<bits/stdc++.h>

using namespace std;

class Solution {
public:
bool canFormArray(vector<int>& arr, vector<vector<int>>& pieces) {
int idx = 0;
while (idx < arr.size()) {
int p_id = -1;
for (int i = 0; i < pieces.size(); i++) {
if (pieces[i][0] == arr[idx]) {
p_id = i;
break;
}
}
if (p_id == -1) {
return false;
}
for (int j = 0; j < pieces[p_id].size(); j++) {
if (arr[idx] != pieces[p_id][j]) {
return false;
}
idx++;
}
}
return idx == arr.size();
}
};
25 changes: 25 additions & 0 deletions solved/LeetCode/Challenges/2020/January/02.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {
if (cloned == nullptr) {
return nullptr;
}
if (cloned->val == target->val) {
return cloned;
}
TreeNode* left = getTargetCopy(original, cloned->left, target);
if (left != nullptr) {
return left;
}
return getTargetCopy(original, cloned->right, target);
}
};

0 comments on commit ddcf7fa

Please sign in to comment.