You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicclassSolution{
publicvoidtraverse(TreeNoderoot){
if(root == null){
return;
}
// do something with roottraverse(root.left);
// do something with roottraverse(root.right);
// do something with root
}
}
Template 2: Divide & Conquer
publicclassSolution{
publicResultTypetraversal(TreeNoderoot){
// null or leftif(root == null){
// do something and return;
}
// Divide 问题分解ResultTypeleft = traversal(root.left);
ResultTyperight = traversal(root.right);
// Conquer 问题合并ResultTyperesult = Mergefromleftandrightreturnresult;
}
}