剑指offer
二叉搜索树的第k个结点
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:473703
本题知识点:
树
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
给定一棵二叉搜索树,请找出其中的第k小的TreeNode结点。
示例1
输入
复制
{5,3,7,2,4,6,8},3
{5,3,7,2,4,6,8},3
返回值
复制
{4}
{4}
说明
按结点数值大小顺序第三小结点的值为4
说明:本题目包含复杂数据结构TreeNode,
点此查看相关信息
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
/* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { TreeNode KthNode(TreeNode pRoot, int k) { } }
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; */ class Solution { public: TreeNode* KthNode(TreeNode* pRoot, int k) { } };
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # 返回对应节点TreeNode def KthNode(self, pRoot, k): # write code here
/* public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; } }*/ class Solution { public TreeNode KthNode(TreeNode pRoot, int k) { // write code here } }
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function KthNode(pRoot, k) { // write code here } module.exports = { KthNode : KthNode };
val = $val; } }*/ function KthNode($pRoot, $k) { // write code here }
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function KthNode(pRoot, k) { // write code here }
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # 返回对应节点TreeNode def KthNode(self, pRoot, k): # write code here
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * * @param pRoot TreeNode类 * @param k int整型 * @return TreeNode类 */ func KthNode( pRoot *TreeNode , k int ) *TreeNode { // write code here }
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * * @param pRoot TreeNode类 * @param k int整型 * @return TreeNode类 */ struct TreeNode* KthNode(struct TreeNode* pRoot, int k ) { // write code here }