We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 556d100 commit 3bd209cCopy full SHA for 3bd209c
src/1305-all-elements-in-two-binary-search-trees/index.js
@@ -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