Advertisement
momo2345

Search in BST

May 25th, 2023
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1.  class Solution {
  2.  public:
  3.     TreeNode* searchBST(TreeNode* root, int val) {
  4.         if(root == nullptr) return nullptr;
  5.         if( root->val == val)
  6.             return root;
  7.         else{
  8.             if(val < root->val) return searchBST(root->left, val);
  9.             else return searchBST(root->right, val);
  10.         }
  11.        return NULL;
  12.     }
  13.  };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement