Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1<=x<=k2 and x is a key of given BST. Return all the keys in ascending order.
Example
If k1 = 10
and k2 = 22
, then your function should return[12, 20, 22]
.
20
/ \
8 22
/ \
4 12
这道题也是Google的面经题。
Solution:
public List<Integer> searchRange(TreeNode root, int k1, int k2) { List<Integer> result = new ArrayList<>(); help(result, root, k1, k2); return result; } private void help(List<Integer> result, TreeNode node, int k1, int k2) { if(node == null) return; if(node.val >= k1) { help(result, node.left, k1, k2); } if(node.val >= k1 && node.val <= k2) { result.add(node.val); } if(node.val > k2) return; help(result, node.right, k1, k2); }
相关推荐
amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gzamoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz ...
sqlite-netFx46-binary-bundle-x64-2015-1.0.113.0.zip
前端开源库-binary-search-tree二进制搜索树,不同的二进制搜索树实现,包括自平衡树(AVL)
sqlite-netFx40-binary-bundle-Win32-2010-1.0.94.0 解决 “异常来自 HRESULT:0x8007007E” 这个问题。
Construct Binary Tree from Preorder and Inorder Traversal 根据先序,中序建立二叉树
sqlite framework 4.5.1 版本, sqlite-netFx451-binary-x64-2013-1.0.106.0.zip
BinaryTree-BinaryTree
sqlite-netFx40-binary-x64-2010-1.0.94.0.zip sqlite 64操作系统api dll,官方很难下载,在这提供方便下载。
sqlite 库,包含所有的dll文件,解压文件,将里面的SQLite.Interop.dll拷贝到SQLiteExpert的安装目录。
二叉树的结构特征,以及链式存储结构的特点及程序设计方法
sqlite framework 4.0 版本, sqlite-netFx40-binary-x64-2010-1.0.106.0.zip
最优二叉搜索树算法,Optimal binary search tree algorithm
支持sqlite 数据块加密解密插件。解压文件,将里面的SQLite.Interop.dll拷贝到SQLiteExpert的安装目录然后启动SQLiteExpert,Tools->Options->SQLite library,选择带SQLite.Interop.dll的项即可。
sqlite-netFx40-static-binary-x64-2010-1.0.112.0.zip;混合编译,支持32位和64位。
armadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w(binary).stlarmadillo-V17w...
sqlite-netFx451-static-binary-bundle-x64-2013-1.0.112.0.zip 下错版本了,官网下的好慢,免费分享
sqlite framework 4.6 版本, sqlite-netFx46-binary-x64-2015-1.0.106.0.zip
jackson-dataformats-binary, 标准Jackson二进制格式后端的Uber项目 概述这是 Jackson的标准二进制dataformat后端的多模块umbrella项目。当前包括的是:AvroCBORProtobuf微笑许可证所有模块均在 Apache许可 2.0 许可...
mojarra-2.1.2-FCS-binary JSF 开发Jar包 Java Server Face
binary-search-tree-davidalejandrolazopampa:由GitHub Classroom创建的binary-search-tree-davidalejandrolazopampa