https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/

본인이 조상값일 경우를 상정하는 경우까지 포함

class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if(root == NULL) return NULL;
        if(root == p || root == q) return root;
        TreeNode* left;
        TreeNode* right;
        
        left = lowestCommonAncestor(root->left, p, q);
        
        right = lowestCommonAncestor(root->right, p, q);
        
        if(left && right) return root;
        return left? left:right;
    }
};