public static TreeNode commonAncestorRec(TreeNode root, TreeNode p, TreeNode q) {
        if(root == null) {
            return null;
        }
        if(root==p || root==q) {
            return root;
        }

        boolean isPInLeft = isIn(root.left, p);		// 判断p是否在树的左侧
        boolean isQInLeft = isIn(root.left, q);		// 判断q是否在树的左侧

        if(isPInLeft != isQInLeft){			// 如果一个在左侧一个在右侧，则公共祖先必然是root
            return root;
        }

        if(isPInLeft) {		// p，q都在左侧
            return commonAncestorRec(root.left, p, q);
        } else{				// p，q都在右侧
            return commonAncestorRec(root.right, p, q);
        }
    }