File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,218 LeetCode solutions in JavaScript
1
+ # 1,219 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
987
987
1301|[ Number of Paths with Max Score] ( ./solutions/1301-number-of-paths-with-max-score.js ) |Hard|
988
988
1302|[ Deepest Leaves Sum] ( ./solutions/1302-deepest-leaves-sum.js ) |Medium|
989
989
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|
990
991
1309|[ Decrypt String from Alphabet to Integer Mapping] ( ./solutions/1309-decrypt-string-from-alphabet-to-integer-mapping.js ) |Easy|
991
992
1313|[ Decompress Run-Length Encoded List] ( ./solutions/1313-decompress-run-length-encoded-list.js ) |Easy|
992
993
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 number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments