Two methods:
1. Traverse
2. Divide & Conquer
1 // Traverse: usually do not have return value 2 public class Solution { 3 public void traverse(TreeNode root) { 4 if (root == null) 5 return; 6 traverse(root.left); 7 traverse(root.right); 8 } 9 } 10 11 // Divide & Conquer: usually have return value 12 public class Solution { 13 public ResultType traversal(TreeNode root) { 14 if (root == null) { 15 // do something and return 16 } 17 18 // Divide 19 ResultType left = traversal(root.left); 20 ResultType right = traversal(root.right); 21 22 // Conquer 23 ResultType merge = Merge from left to right. 24 return result; 25 } 26 }