diff options
author | terminaldweller <thabogre@gmail.com> | 2022-04-14 04:41:01 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-04-14 04:41:01 +0000 |
commit | df13a09c6d56444126250ef724960362feb43615 (patch) | |
tree | e06e014a213a07e0e8c16c3e058c7e455e2a19c4 /700/main.cpp | |
parent | update (diff) | |
download | leetcode-df13a09c6d56444126250ef724960362feb43615.tar.gz leetcode-df13a09c6d56444126250ef724960362feb43615.zip |
update
Diffstat (limited to '700/main.cpp')
-rw-r--r-- | 700/main.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/700/main.cpp b/700/main.cpp new file mode 100644 index 0000000..061bb31 --- /dev/null +++ b/700/main.cpp @@ -0,0 +1,30 @@ + +#include "header.hpp" + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode() : val(0), left(nullptr), right(nullptr) {} + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + TreeNode(int x, TreeNode *left, TreeNode *right) + : val(x), left(left), right(right) {} +}; + +class Solution { +public: + TreeNode *searchBST(TreeNode *root, int val) { + while (root) { + if (root->val > val) { + root = root->left; + } else if (root->val < val) { + root = root->right; + } else { + return root; + } + } + return nullptr; + } +}; + +int main(int argc, char **argv) { return 0; } |