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 053f8c9 commit 78cdc6aCopy full SHA for 78cdc6a
maximum-depth-of-binary-tree/RiaOh.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
10
+ * @param {TreeNode} root
11
+ * @return {number}
12
13
+var maxDepth = function (root) {
14
+ if (root === null) {
15
+ return 0;
16
+ } else {
17
+ const leftDepth = maxDepth(root.left);
18
+ const rightDepth = maxDepth(root.right);
19
+
20
+ return Math.max(leftDepth, rightDepth) + 1;
21
+ }
22
+};
0 commit comments