思路:
开辟数组;
中序遍历;
索引找值。
换成C语言风格。
要不然太依赖STL了。
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void dfs(struct TreeNode* root, int* count, int* returnSize){
if(!root) return ;
dfs(root->left, count, returnSize);
count[(*returnSize)++] = root->val;
dfs(root->right, count, returnSize);
}
int kthLargest(struct TreeNode* root, int k){
int* count = (int *)malloc(10000* sizeof(int));
int i = 0;
dfs(root, count, &i);
return count[i - k];
}