More test cases needed


  • 0
    A
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
    	while (root != null) {
    		if (p.val < root.val && q.val < root.val) {
    			root = root.left;
    		} else if (p.val > root.val && q.val > root.val) {
    			root = root.right;
    		} else {
    			return root;
    		}
    	}
    	return null;
    }
    

    My code will fail the test case: [2,2,#,1] with nodes 2(second 2) and 1. The anwser should be 2(second 2) but my program output 2(first 2), which is still be accepted.


  • 0

    Your tree has a duplicate number. That's not considered a valid binary search tree (at least not here) and thus this is an invalid test case.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.