Python•maximum-depth-of-binary-tree/synced-solution.py
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return class="syntax-number">0
return class="syntax-number">1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
C++•maximum-depth-of-binary-tree/synced-solution.cpp
class Solution {
public:
int maxDepth(TreeNode* root) {
if (!root) return class="syntax-number">0;
return class="syntax-number">1 + max(maxDepth(root->left), maxDepth(root->right));
}
};
TypeScript•maximum-depth-of-binary-tree/synced-solution.ts
function maxDepth(root: TreeNode | null): number {
if (!root) return class="syntax-number">0;
return class="syntax-number">1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}