/**
- struct TreeNode {
- int val;
- struct TreeNode *left;
- struct TreeNode *right;
- };
- C语言声明定义全局变量请加上static,防止重复定义 / /*
- 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
- @param proot TreeNode类
- @param k int整型
- @return int整型 */ static g_temp[1000]; static int g_num;
void trasver_tree_midd_order(struct TreeNode * pRoot) { if (pRoot == NULL) return;
trasver_tree_midd_order(pRoot->left);
g_temp[g_num++] = pRoot->val;
trasver_tree_midd_order(pRoot->right);
} int KthNode(struct TreeNode* proot, int k ) { // write code here if (proot == NULL || k == 0) return -1;
trasver_tree_midd_order(proot);
if (g_num < k) return -1;
return g_temp[k - 1];
}