recursion programming
1 public class Solution { 2 public boolean isSymmetric(TreeNode root) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(root == null) 6 return true; 7 return checkTwoSubtree(root.left, root.right); 8 } 9 private boolean checkTwoSubtree(TreeNode leftTree, TreeNode rightTree) 10 { 11 if(leftTree == null && rightTree == null) 12 return true; 13 if(leftTree == null || rightTree == null) 14 return false; 15 if(leftTree.val != rightTree.val) 16 return false; 17 return checkTwoSubtree(leftTree.left, rightTree.right) && checkTwoSubtree(leftTree.right, rightTree.left); 18 } 19 }