1. 题目
2. 方法一中序遍历法
2.1. 代码
class Solution {
public:
int kthSmallest(TreeNode* root, int k){
stack<TreeNode*> tempstack;
tempstack.push(root);
int i=1;
while(root!=NULL||!tempstack.empty()){
if(root!=NULL){
tempstack.push(root);
root=root->left;
}
else{
if(i<k){
root=tempstack.top()->right;
tempstack.pop();
i++;
}
else break;
}
}
return (tempstack.top())->val;
}
};