Boundary of Binary Tree
@ctfu the problem says no duplicate nodes, not no duplicate values.
it's really a great and clear solution
how about putting the right.add() to the end just like a postorder traverse?
No one has replied
simplify the code.
@eaglesky Thanks! You are right, "root.left != null" and "root.right != null" can be removed without causing any damage. But I am leaving it there for now as it might help understand the logic.
It 's expensive and not necessary to use hash to check whether the node is visited.
Because there are at most three node may visited twice or more, which are root, left most leaf and right most leaf node.
Here is the code for reference,
@fallcreek oh sorry,there must be a mistake ,thank you ...
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.