TreeNode buildBST(int[] a, int start, int end) { if (start > end) return null; int mid = (start + end) / 2; TreeNode n = new TreeNode(a[mid]); n.left = buildBST(a, start, mid - 1); n.right = buildBST(a, mid + 1, end); return n; }
public void invertTreeInternal(TreeNode root) { if (root == null) return; TreeNode temp = root.right; root.right = root.left; root.left = temp; invertTree(root.left); invertTree(root.right); }