nbfuhao avatar

[LeetCode] Validate Binary Search Tree in Objective C

nbfuhao

Published: 06 Mar 2017 › Updated: 06 Mar 2017[LeetCode] Validate Binary Search Tree in Objective C

[LeetCode] Validate Binary Search Tree in Objective C

LeetCode: Validate Binary Search Tree in Objective C


typedef struct {
    int value;
    struct TreeNode *left;
    struct TreeNode *right;
 } TreeNode;

-(BOOL)isValidBST:(TreeNode *)node
{
   return (valid:node minValue:INT_MIN maxValue:INT_MAX);
}

-(BOOL)valid:(TreeNode *)treeNode minValue:(int)minValue maxValue(int)max
{
  if (!treeNode) return true;
  return treeNode.value > minValue && treeNode.value < maxValue
    && (valid:treeNode.left, minValue, treeNode.value) 
    && (valid:treeNode.right, treeNode.value, maxValue) 
}

Leave [LeetCode] Validate Binary Search Tree in Objective C to:

Written by

Software Engineer, writing Swift and Objective codes

Read more #programming posts


Best Posts From nbfuhao

We have not curated any of nbfuhao's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From nbfuhao