aboutsummaryrefslogtreecommitdiffstats
path: root/700/main.cpp
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-04-14 04:41:01 +0000
committerterminaldweller <thabogre@gmail.com>2022-04-14 04:41:01 +0000
commitdf13a09c6d56444126250ef724960362feb43615 (patch)
treee06e014a213a07e0e8c16c3e058c7e455e2a19c4 /700/main.cpp
parentupdate (diff)
downloadleetcode-df13a09c6d56444126250ef724960362feb43615.tar.gz
leetcode-df13a09c6d56444126250ef724960362feb43615.zip
update
Diffstat (limited to '700/main.cpp')
-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; }