leetcode

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

0783.cpp (539B)


0 class Solution { 1 public: 2 int minDiffInBST(TreeNode *root) { 3 stack<TreeNode *> st; 4 int res = INT_MAX; 5 TreeNode *prev = new TreeNode(INT_MAX); 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 res = min(res, abs(prev->val - root->val)); 15 prev = root; 16 root = root->right; 17 } 18 return res; 19 } 20 };