- 二叉树的最大深度(第101题)
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
def iteration(p,q):
if p == None:
return q == None
if q == None:
return p == None
if p.val == q.val:
return (iteration(p.left,q.right) and iteration(p.right,q.left))
if p.val != q.val:
return False
if root == None:
return True
else:
return iteration(root.left,root.right)
- 二叉树的最大深度(第104题)
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root == None:
return 0
else:
return max(self.maxDepth(root.left),self.maxDepth(root.right)) + 1