From dc1f0c4c0096013799416664894c5194dc7e1f52 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- store/works/solutions/leetcode/cpp/98.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 store/works/solutions/leetcode/cpp/98.cpp (limited to 'store/works/solutions/leetcode/cpp/98.cpp') diff --git a/store/works/solutions/leetcode/cpp/98.cpp b/store/works/solutions/leetcode/cpp/98.cpp new file mode 100644 index 0000000..73cefa0 --- /dev/null +++ b/store/works/solutions/leetcode/cpp/98.cpp @@ -0,0 +1,29 @@ +#include + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +#include + +class Solution +{ +public: + bool dfs(TreeNode *node, long long min, long long max) + { + if (node == nullptr) + return true; + if (node->val <= min || node->val >= max) + return false; + return dfs(node->left, min, node->val) && dfs(node->right, node->val, max); + } + + bool isValidBST(TreeNode *root) + { + return dfs(root, std::numeric_limits::min(), std::numeric_limits::max()); + } +}; -- cgit v1.2.3