leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0098.cpp (492B)
0 class Solution { 1 public: 2 bool isValidBST(TreeNode *root) { 3 stack<TreeNode *> st; 4 long prev = LONG_MIN; 5 while (true) { 6 while (root) { 7 st.push(root); 8 root = root->left; 9 } 10 if (st.empty()) break; 11 root = st.top(); 12 st.pop(); 13 if (root->val <= prev) return false; 14 prev = root->val; 15 root = root->right; 16 } 17 return true; 18 } 19 };