GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/tree/Yu/104_maxDepth.py at master · deba999/leetcode Expand file tree/ Copy path104_maxDepth.pyMore file actions 36 lines (30 loc) · 829 Bytes / Copy path104_maxDepth.pyFile metadata and controls36 lines (30 loc) · 829 Bytes 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. |