Maximum Depth of Binary Tree

Recursive Call

Given the root of a binary tree, return its maximum depth.

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

์ž๋ฃŒ๊ตฌ์กฐ : N/A

์•Œ๊ณ ๋ฆฌ์ฆ˜ 1. ์žฌ๊ท€ํ˜ธ์ถœ์„ ํ†ตํ•ด ์žŽ๋…ธ๋“œ๊นŒ์ง€ ๋‚ด๋ ค๊ฐ„๋‹ค. - Null์„ ๋งŒ๋‚  ๋•Œ๊นŒ์ง€ ์žฌ๊ท€ํ˜ธ์ถœ๋กœ ์ญ‰ ๋‚ด๋ ค๊ฐ„๋‹ค! 2. Null์„ ๋งŒ๋‚˜๋ฉด ๋น„๋กœ์†Œ ๊ฐ’์„ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค! 0 ๋˜๋Š” 1. - left:0, right:0, Math.max(0,0)+1 = 1

์•Œ๊ณ ๋ฆฌ์ฆ˜์„ Java๋กœ

Last updated

Was this helpful?