aboutsummaryrefslogtreecommitdiffstats
path: root/700/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--700/main.cpp30
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; }