Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3bd209c

Browse files
✨ all elements in two binary search trees
1 parent 556d100 commit 3bd209c

File tree

1 file changed

+26
-0
lines changed
  • src/1305-all-elements-in-two-binary-search-trees

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root1
10+
* @param {TreeNode} root2
11+
* @return {number[]}
12+
*/
13+
var getAllElements = function (root1, root2) {
14+
const res = [];
15+
dfs(root1);
16+
dfs(root2);
17+
res.sort((x, y) => x - y);
18+
return res;
19+
20+
function dfs(node) {
21+
if (!node) return;
22+
res.push(node.val);
23+
dfs(node.left);
24+
dfs(node.right);
25+
}
26+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /