2019-09-03 08:52:24 -07:00

21 lines
421 B
C

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* searchBST(struct TreeNode* root, int val){
if(!root)
return NULL;
if(root->val == val)
return root;
else if (root->val > val)
return searchBST(root->left, val);
else
return searchBST(root->right, val);
}