One line function


  • 0
    C

    The night is late and I'm bored coding in a bar...I know it's trivial but it's a bit fun : )

    class Solution:
    
        def isValidBST(self, root, leftLim=-float('inf'), rightLim=float('inf')):
    	    return False if root and (((root.val<=leftLim or root.val>=rightLim) or (root.left and (root.left.val>=root.val or not self.isValidBST(root.left, leftLim=leftLim,rightLim=root.val))) or (root.right and (root.right.val<=root.val or not self.isValidBST(root.right, leftLim=root.val, rightLim=rightLim))))) else True

Log in to reply
 

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