commit 3b9b684db3c3ef2f0eed7afd90219acfd157fc7c
parent fdeaff3161d68609e4b8c3fac504b84a4a05e213
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 8 Nov 2023 17:55:21 +0000
Daily Problem and 1 Random Problem
Diffstat:
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/Problems/0623.cpp b/Problems/0623.cpp
@@ -0,0 +1,21 @@
+class Solution {
+ public:
+ TreeNode *addOneRow(TreeNode *root, int val, int depth) const {
+ if (depth == 1) return new TreeNode(val, root, nullptr);
+ queue<TreeNode *> q;
+ q.push(root);
+ for (int lvl = 2; !q.empty(); lvl++) {
+ for (int k = q.size(); k > 0; k--) {
+ TreeNode *root = q.front();
+ q.pop();
+ if (root->left) q.push(root->left);
+ if (root->right) q.push(root->right);
+ if (lvl == depth) {
+ root->left = new TreeNode(val, root->left, nullptr);
+ root->right = new TreeNode(val, nullptr, root->right);
+ }
+ }
+ }
+ return root;
+ }
+};
diff --git a/Problems/2849.cpp b/Problems/2849.cpp
@@ -0,0 +1,8 @@
+class Solution {
+ public:
+ bool isReachableAtTime(int sx, int sy, int fx, int fy, int t) const {
+ const int x = abs(fx - sx), y = abs(fy - sy);
+ if (!x && !y && t == 1) return false;
+ return max(x, y) <= t;
+ }
+};
diff --git a/README.md b/README.md
@@ -355,6 +355,7 @@ for solving problems.
| 0609 | Medium | [Find Duplicate File in System](Problems/0609.cpp) |
| 0617 | Easy | [Merge Two Binary Trees](Problems/0617.cpp) |
| 0621 | Medium | [Task Scheduler](Problems/0621.cpp) |
+| 0623 | Medium | [Add One Row to Tree](Problems/0623.cpp) |
| 0636 | Medium | [Exclusive Time of Functions](Problems/0636.cpp) |
| 0637 | Easy | [Average of Levels in Binary Tree](Problems/0637.cpp) |
| 0643 | Easy | [Maximum Average Subarray I](Problems/0643.cpp) |
@@ -897,6 +898,7 @@ for solving problems.
| 2785 | Medium | [Sort Vowels in a String](Problems/2785.cpp) |
| 2799 | Medium | [Count Complete Subarrays in an Array](Problems/2799.cpp) |
| 2807 | Medium | [Insert Greatest Common Divisors in Linked List](Problems/2807.cpp) |
+| 2849 | Medium | [Determine if a Cell Is Reachable at a Given Time](Problems/2849.cpp) |
| 2856 | Medium | [Minimum Array Length After Pair Removals](Problems/2856.cpp) |
| 2895 | Medium | [Minimum Processing Time](Problems/2895.cpp) |
| 2900 | Medium | [Longest Unequal Adjacent Groups Subsequence I](Problems/2900.cpp) |