## [LintCode] Convert Sorted Array to Binary Search Tree With Minimal Height

public TreeNode sortedArrayToBST(int[] A) { // write your code here return rec(A,0, A.length – 1); } public TreeNode rec(int[] A, int start, int end) { if(start > end) return null; int mid = start + (end – start) / 2; TreeNode root = new TreeNode(A[mid]); root.left = rec(A,start,mid-1); root.right = rec(A,mid+1, end); return root; }

## [LintCode] Subtree

public boolean isSubtree(TreeNode T1, TreeNode T2) { // write your code here if(T2 == null) return true; else if(T1 == null) return false; else return isSameTree(T1, T2) || isSubtree(T1.left, T2) || isSubtree(T1.right, T2); } public boolean isSameTree(TreeNode T1, TreeNode T2) { if(T1 == null && T2 == null) return true; if(T1 == null || T2 […]

## [LintCode] Maximum Depth of Binary Tree

public int maxDepth(TreeNode root) { // write your code here if(root == null) return 0; return Math.max(maxDepth(root.left), maxDepth(root.right))+1; }

## [LintCode] Invert Binary Tree

public void invertBinaryTree(TreeNode root) { // write your code here if(root == null) return; invertBinaryTree(root.left); invertBinaryTree(root.right); TreeNode left = root.left; root.left = root.right; root.right = left; }