#235.Lowest Common Ancestor of a Binary Search Tree [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/

class Solution {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        //check on the left side
        if(root.val > p.val && root.val > q.val)
            return lowestCommonAncestor(root.left, p, q);
        //check on the right side
        if(root.val < p.val && root.val < q.val)
            return lowestCommonAncestor(root.right, p, q);

        return root;

    }
}