GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/tree/Yu/104_maxDepth.py at master · deba999/leetcode

Expand file tree

/

104_maxDepth.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
36 lines (30 loc) · 829 Bytes
/

104_maxDepth.py

Copy path

File metadata and controls

36 lines (30 loc) · 829 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Yu Zhou
# ****************
# Descrption:
# Given a binary tree, find its maximum depth.
# ****************
# 思路:
# 基础题,确保有Root就行。然后递归
# ****************
# Final Solution *
# ****************
class Solution(object):
def maxDepth(self, root):
if not root:
return 0
else:
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
# ********************
# Divide and Conquer *
# ********************
class Solution(object):
def maxDepth(self, root):
if not root:
return 0
else:
# using Divide and Conquer
left = self.maxDepth(root.left)
right = self.maxDepth(root.right)
return max(left, right) + 1
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.