LintCode 11. Search Range in Binary Search Tree
2018-02-12 11:00
225 查看
题目
思路
二叉树中序非递归遍历。代码
""" Definition of TreeNode: class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None """ class Solution: """ @param: root: param root: The root of the binary search tree @param: k1: An integer @param: k2: An integer @return: return: Return all keys that k1<=key<=k2 in ascending order """ def searchRange(self, root, k1, k2): # write your code here res_list = [] stack = [] while root or len(stack): while root: stack.append(root) root = root.left if len(stack): root = stack[-1] stack.pop(-1) if root.val >= k1 and root.val <= k2: res_list.append(root.val) root = root.right return res_list
相关文章推荐
- Lintcode 11 Search Range in Binary Search Tree
- Lintcode_11 Search Range in Binary Search Tree
- LintCode-Search Range in Binary Search Tree
- [Lintcode] Search Range in Binary Search Tree
- Lintcode: Search Range in Binary Search Tree
- 20150707 lintcode 总结 Search Range in Binary Search Tree
- lintcode:Search Range in Binary Search Tree
- lintcode-medium-Search Range in Binary Search Tree
- Search Range in Binary Search Tree
- #11 Search Range in Binary Search Tree
- Lintcode11 Search Range in Binary Search Tree solution 题解
- [Lintcode] Insert Node in a Binary Search Tree
- lintcode-easy-Insert Node in a Binary Search Tree
- [刷题]Search Range in Binary Search Tree
- Search Range in Binary Search Tree
- lintcode search-range-in-binary-search-tree 二叉搜索树中搜索区间
- Lintcode - Remove Node in Binary Search Tree
- 递归-----Search Range in Binary Search Tree
- LintCode-Remove node in Binary Search Tree
- LintCode Search Range in Binary Search Tree