Skip to content

Instantly share code, notes, and snippets.

@codetalks-new
Created June 15, 2015 00:26
Show Gist options
  • Save codetalks-new/b585b873f405d7f80ccc to your computer and use it in GitHub Desktop.
Save codetalks-new/b585b873f405d7f80ccc to your computer and use it in GitHub Desktop.
func maxDepth_r(root:TreeNode?) -> Int{
if root == nil{
return 0
}
if root?.left == nil && root?.right == nil{
return 1
}
let rightDepth = maxDepth_r(root?.left)
let leftDepth = maxDepth_r(root?.right)
let childDepth = max(leftDepth,rightDepth)
return childDepth + 1
}
@codetalks-new
Copy link
Author

对于这个题目而言,使用递归的解法一般的效率也还过得去.至少不会超时.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment