现在的位置: 首页 > 综合 > 正文

Ch4.8: find all the path that a Binary tree sums up to a given value, may/maynot have parent pointer

2014年07月07日 ⁄ 综合 ⁄ 共 275字 ⁄ 字号 评论关闭

In this problem, we should consider the path to the bottom, instead of hit-and-run. As a result, the recursive starts summation from the children up to their parents not from up to down.

For example:

The given sums up value is 8:

then these are all correct paths:

8;

8=-2=2;

2=0=6;

2=0=6=-1=1;

Here is the full code. Very well design.

【上篇】
【下篇】

抱歉!评论已关闭.