Skip to content

Commit 045aa2b

Browse files
committedApr 12, 2025
Add solution #1379
1 parent 3e0ea65 commit 045aa2b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,264 LeetCode solutions in JavaScript
1+
# 1,265 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1050,6 +1050,7 @@
10501050
1375|[Number of Times Binary String Is Prefix-Aligned](./solutions/1375-number-of-times-binary-string-is-prefix-aligned.js)|Medium|
10511051
1376|[Time Needed to Inform All Employees](./solutions/1376-time-needed-to-inform-all-employees.js)|Medium|
10521052
1377|[Frog Position After T Seconds](./solutions/1377-frog-position-after-t-seconds.js)|Hard|
1053+
1379|[Find a Corresponding Node of a Binary Tree in a Clone of That Tree](./solutions/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.js)|Easy|
10531054
1380|[Lucky Numbers in a Matrix](./solutions/1380-lucky-numbers-in-a-matrix.js)|Easy|
10541055
1389|[Create Target Array in the Given Order](./solutions/1389-create-target-array-in-the-given-order.js)|Easy|
10551056
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* 1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree
3+
* https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/
4+
* Difficulty: Easy
5+
*
6+
* Given two binary trees original and cloned and given a reference to a node target in the original
7+
* tree.
8+
*
9+
* The cloned tree is a copy of the original tree.
10+
*
11+
* Return a reference to the same node in the cloned tree.
12+
*
13+
* Note that you are not allowed to change any of the two trees or the target node and the answer
14+
* must be a reference to a node in the cloned tree.
15+
*/
16+
17+
/**
18+
* Definition for a binary tree node.
19+
* function TreeNode(val) {
20+
* this.val = val;
21+
* this.left = this.right = null;
22+
* }
23+
*/
24+
/**
25+
* @param {TreeNode} original
26+
* @param {TreeNode} cloned
27+
* @param {TreeNode} target
28+
* @return {TreeNode}
29+
*/
30+
var getTargetCopy = function(original, cloned, target) {
31+
return traverse(original, cloned);
32+
33+
function traverse(originalNode, clonedNode) {
34+
if (!originalNode) return null;
35+
if (originalNode === target) return clonedNode;
36+
37+
const leftResult = traverse(originalNode.left, clonedNode.left);
38+
if (leftResult) return leftResult;
39+
40+
return traverse(originalNode.right, clonedNode.right);
41+
}
42+
};

0 commit comments

Comments
 (0)