Skip to content

Commit 0b20937

Browse files
committed
Add solution #1305
1 parent f6bc1d8 commit 0b20937

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,218 LeetCode solutions in JavaScript
1+
# 1,219 LeetCode solutions in JavaScript
22

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

@@ -987,6 +987,7 @@
987987
1301|[Number of Paths with Max Score](./solutions/1301-number-of-paths-with-max-score.js)|Hard|
988988
1302|[Deepest Leaves Sum](./solutions/1302-deepest-leaves-sum.js)|Medium|
989989
1304|[Find N Unique Integers Sum up to Zero](./solutions/1304-find-n-unique-integers-sum-up-to-zero.js)|Easy|
990+
1305|[All Elements in Two Binary Search Trees](./solutions/1305-all-elements-in-two-binary-search-trees.js)|Medium|
990991
1309|[Decrypt String from Alphabet to Integer Mapping](./solutions/1309-decrypt-string-from-alphabet-to-integer-mapping.js)|Easy|
991992
1313|[Decompress Run-Length Encoded List](./solutions/1313-decompress-run-length-encoded-list.js)|Easy|
992993
1317|[Convert Integer to the Sum of Two No-Zero Integers](./solutions/1317-convert-integer-to-the-sum-of-two-no-zero-integers.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 1305. All Elements in Two Binary Search Trees
3+
* https://leetcode.com/problems/all-elements-in-two-binary-search-trees/
4+
* Difficulty: Medium
5+
*
6+
* Given two binary search trees root1 and root2, return a list containing all the integers from
7+
* both trees sorted in ascending order.
8+
*/
9+
10+
/**
11+
* Definition for a binary tree node.
12+
* function TreeNode(val, left, right) {
13+
* this.val = (val===undefined ? 0 : val)
14+
* this.left = (left===undefined ? null : left)
15+
* this.right = (right===undefined ? null : right)
16+
* }
17+
*/
18+
/**
19+
* @param {TreeNode} root1
20+
* @param {TreeNode} root2
21+
* @return {number[]}
22+
*/
23+
var getAllElements = function(root1, root2) {
24+
const values = [];
25+
26+
inorder(root1);
27+
inorder(root2);
28+
29+
return values.sort((a, b) => a - b);
30+
31+
function inorder(node) {
32+
if (!node) return;
33+
inorder(node.left);
34+
values.push(node.val);
35+
inorder(node.right);
36+
}
37+
};

0 commit comments

Comments
 (0)