【二叉树】BST第K小值【230. Kth Smallest Element in a BST】
来源:互联网 发布:幻想神域攻略软件 编辑:程序博客网 时间:2024/06/06 07:23
题目链接:https://leetcode.com/problems/kth-smallest-element-in-a-bst/#/discuss
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int kthSmallest(TreeNode* root, int k) { return getOrder(root,k); } // 中序遍历 int getOrder(TreeNode* root,int& k){ if(root){ int t=getOrder(root->left,k); if(!k) return t; k--; if(k) t=getOrder(root->right,k); else t=root->val; return t; } return -1; }};
阅读全文
0 0
- 【二叉树】BST第K小值【230. Kth Smallest Element in a BST】
- LeetCode-230. Kth Smallest Element in a BST (JAVA)二叉树第k小的数字
- Kth Smallest Element in a BST 找二叉搜索树中的第k小的元素
- [leetcode 230]Kth Smallest Element in a BST----求二叉搜索树的第K小值
- leetcode_230. Kth Smallest Element in a BST 求二叉搜索树中的第k小的元素,中序遍历法
- LeetCode OJ 之 Kth Smallest Element in a BST(BST中的第k小元素)
- leetcode230---Kth Smallest Element in a BST(BST中寻找第K小)
- 230. Kth Smallest Element in a BST | 二叉排序树中查找第K小的数
- LeetCode 230. Kth Smallest Element in a BST(二叉搜索树中的第K个元素)
- leetcode 230. Kth Smallest Element in a BST 二叉搜索树BST的中序遍历
- Kth Smallest Element in a BST 寻找二叉排序树中第k小元素
- 230.Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 关于PHP扩展CURL
- ubuntu 14.04下安装opencv
- 计算机视觉学习(导读)
- ajax
- nginx整合php+lua+oracle环境搭建
- 【二叉树】BST第K小值【230. Kth Smallest Element in a BST】
- JavaScript 常用方法
- nginx的启动,重启,停止(windows下)
- boost bind使用指南
- MVC框架-mentawai(10)
- 卷积及其物理意义
- DNS域名解析过程
- Driver中使用的内核机制
- Unity3D 编写游戏运行时间 格式为00:00:00