Failing Javascript Test Case [1,1]


  • 0
    G

    When I submit this it says [1,1] returns 0 when expecting 1. But when I enter the custom testcase it correctly returns 1 so not sure what is going on here?

    let deepest = 0;
                                   
    var findBottomLeftValue = function(root) {
      return search(root,0);
    };
    
    function search(node, depth) {
      let left = 0;
      let right = 0;
      
      if (!node.left && !node.right && depth===0) return node.val;
    
      if (node.left) {
        left = search(node.left, depth+1);
      }
      if (node.right) {
        right = search(node.right, depth+1);
      }
      if (!node.left && !node.right && deepest < depth) {
        deepest = depth;
        return node.val;
      }
      return Math.max(left,right);
    }
    

Log in to reply
 

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