ctci
ctci copied to clipboard
for the CC150 4.9 java version, there is an write
The way at here and in the book can't find the path from leaf to leaf, or any path accrosses two PATH(from root to leaf), you can use your existing example, findSum(root, 9) and you will found the what I mean, your way outputs nothing, but there should be two paths where sum=9.
BTW, your book is awesome!
Correct. It doesn't. This isn't a valid path. Paths are only "down" in a tree.
Well, for the very strict definition, the path might only go down in a tree, however, we knew there was a problem called " find the maximum path sum in a binary tree" , say the tree is 2-1-3, where 1 is the root, 2 and 3 are left and right child respectively, the maximum path sum here should be 6. Back to the question, I think there might be a better solution than the one offered by the book for question 4.9. Any suggestions on the solution?