Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions maximum-depth-of-binary-tree/limlimjo.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공간 복잡도 계산에 대해 어떻게 생각하시는지 설명 해주시면 너무 좋을것 같습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 시간 복잡도: O(n)
// 공간 복잡도: O(n)

/**
* 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) return 0;

let leftDepth = maxDepth(root.left);
let rightDepth = maxDepth(root.right);

return Math.max(leftDepth, rightDepth) + 1;
};