第4天
class Solution {
public int kthSmallest(TreeNode root, int k) {
record = k;
find(root);
return res;
}
int res;
int record;
void find(TreeNode root){
if(root == null)
return;
find(root.left);
record--;
if(record == 0){
res = root.val;
return;
}
find(root.right);
}
}
class Solution {
int sum = 0;
public TreeNode convertBST(TreeNode root) {
exchange(root);
return root;
}
void exchange(TreeNode root){
if(root == null)
return;
exchange(root.right);
root.val = sum += root.val;
exchange(root.left);
}
}