leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0098.cpp (492B)


      1 class Solution {
      2   public:
      3     bool isValidBST(TreeNode *root) {
      4         stack<TreeNode *> st;
      5         long prev = LONG_MIN;
      6         while (true) {
      7             while (root) {
      8                 st.push(root);
      9                 root = root->left;
     10             }
     11             if (st.empty()) break;
     12             root = st.top();
     13             st.pop();
     14             if (root->val <= prev) return false;
     15             prev = root->val;
     16             root = root->right;
     17         }
     18         return true;
     19     }
     20 };