From df13a09c6d56444126250ef724960362feb43615 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Thu, 14 Apr 2022 09:11:01 +0430 Subject: update --- 700/main.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 700/main.cpp (limited to '700/main.cpp') 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; } -- cgit v1.2.3