File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
maximum-depth-of-binary-tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * ์๊ฐ ๋ณต์ก๋:
3
+ * ๋
ธ๋์ ๊ฐฏ์๋งํผ ํ์ํ๋ฏ๋ก, O(n)
4
+ * ๊ณต๊ฐ ๋ณต์ก๋:
5
+ * ์ฌ๊ท ํธ์ถ ์คํ์ ํฌ๊ธฐ๋ ํธ๋ฆฌ๊ฐ ํ์ชฝ์ผ๋ก ์น์ฐ์น ๊ฒฝ์ฐ O(n)๋ก ์ต์
์ด ๋๊ณ ,
6
+ * ๊ท ํ ์กํ ํธ๋ฆฌ์ ๊ฒฝ์ฐ O(log n)์ด๋ค.
7
+ */
8
+ /**
9
+ * Definition for a binary tree node.
10
+ * function TreeNode(val, left, right) {
11
+ * this.val = (val===undefined ? 0 : val)
12
+ * this.left = (left===undefined ? null : left)
13
+ * this.right = (right===undefined ? null : right)
14
+ * }
15
+ */
16
+ /**
17
+ * @param {TreeNode } root
18
+ * @return {number }
19
+ */
20
+ var maxDepth = function ( root ) {
21
+ const dfs = ( node ) => {
22
+ if ( ! node ) return 0 ;
23
+ return Math . max ( dfs ( node . left ) + 1 , dfs ( node . right ) + 1 ) ;
24
+ }
25
+ return dfs ( root ) ;
26
+ } ;
You canโt perform that action at this time.
0 commit comments