C++ dfs using properties of a BST
dfs.\n\nIf the target is smaller than current node->val, look left.\nIf the target is larger than current node->val, look right.\nIf it is equal set the ans\n\n
dfs.\n\nIf the target is smaller than current node->val, look left.\nIf the target is larger than current node->val, look right.\nIf it is equal set the ans\n\nSolved live on stream.  Everyday 6pm PT.  Check profile for link.\n\n```\nclass Solution {\n    void dfs(TreeNode* root, int val, TreeNode*& ans) {\n        if(!root) return;\n    \n        if(root->val == val) {\n            ans = root;\n        } else if(root->val > val) {\n            dfs(root->left, val, ans);\n        } else if(root->val < val) {\n            dfs(root->right, val, ans);\n        }\n        \n    }\npublic:\n    TreeNode* searchBST(TreeNode* root, int val) {\n        TreeNode* ans = nullptr;\n        dfs(root, val, ans);\n        \n        return ans;\n        \n    }\n};\n```
[]