diff --git a/maximum-depth-of-binary-tree/RiaOh.js b/maximum-depth-of-binary-tree/RiaOh.js new file mode 100644 index 000000000..67d89ab83 --- /dev/null +++ b/maximum-depth-of-binary-tree/RiaOh.js @@ -0,0 +1,22 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number} + */ +var maxDepth = function (root) { + if (root === null) { + return 0; + } else { + const leftDepth = maxDepth(root.left); + const rightDepth = maxDepth(root.right); + + return Math.max(leftDepth, rightDepth) + 1; + } +}; diff --git a/merge-two-sorted-lists/RiaOh.js b/merge-two-sorted-lists/RiaOh.js new file mode 100644 index 000000000..978f23a57 --- /dev/null +++ b/merge-two-sorted-lists/RiaOh.js @@ -0,0 +1,34 @@ +/** + * Definition for singly-linked list. + * function ListNode(val, next) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + */ +/** + * @param {ListNode} list1 + * @param {ListNode} list2 + * @return {ListNode} + */ +var mergeTwoLists = function (list1, list2) { + const node = new ListNode(); + let tail = node; + + while (list1 && list2) { + if (list1.val < list2.val) { + tail.next = list1; + list1 = list1.next; + } else { + tail.next = list2; + list2 = list2.next; + } + tail = tail.next; + } + + if (list2) { + tail.next = list2; + } else if (list1) { + tail.next = list1; + } + return node.next; +};