leetcode

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

0230.cpp (416B)


0 class Solution {
1 public:
2 int kthSmallest(TreeNode *root, int k) {
3 stack<TreeNode *> st;
4 while (true) {
5 while (root) {
6 st.push(root);
7 root = root->left;
8 }
9 if (st.empty()) break;
10 root = st.top(), st.pop();
11 if (!--k) return root->val;
12 root = root->right;
13 }
14 return -1;
15 }
16 };