class Solution {
public:
    TreeNode* searchBST(TreeNode* root, int val) {
        if (root == NULL)
        {
            return nullptr;
        }
        if (root->val == val)
        {
            return root;
        }
        else if (root->val > val)
        {
            return searchBST(root -> left, val);
        }
        else//root->val>val 
        {
            return searchBST(root->right, val);
        }
    }
};

 

posted on 2018-09-27 18:56  Sempron2800+  阅读(122)  评论(0编辑  收藏  举报