JS Solution: recursive (accepted)


  • 0
    T

    'use strict'
    const helper = (node, min, max) =>
    !node || (
    (node.val > min && node.val < max)
    && helper(node.left, min, node.val)
    && helper(node.right, node.val, max)
    )

    const isValidBST = root => helper(root, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);


Log in to reply
 

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