Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

http://yucoding.blogspot.com/2012/12/leetcode-question-13-binary-tree.html

Usually for tree problems, it is either recursion or traversal. For this one, it is obviously by recursion, but.. it utilizes recursion in a highly flexible manner. It is not an easy one.

1. When dfs method return, it returns the path with larger sum - only one path: could be root + left, and root + right

2. When checking current max sum path, left\right\root should be involved all, because such a path could be anything.

 

posted on 2014-08-15 08:11  Tonix  阅读(108)  评论(0编辑  收藏  举报