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