数据结构-树
Peppermint__
这个作者很懒,什么都没留下…
展开
-
二叉树的遍历 迭代 LeetCode 94 144 145
这里简要介绍一下树的迭代方式遍历前序遍历 leetcode 94 使用栈来模拟递归,出栈时候访问结点。前序遍历先访问左子树,再访问右子树,那么入栈时相反,即先入右子树,再入左子树。那么出栈的时候就是前序遍历的顺序。 class PreOrder { ArrayList<Integer> result = new ArrayList<>(); public ArrayList<I原创 2018-02-27 11:23:16 · 148 阅读 · 0 评论 -
LeetCode 96. Unique Binary Search Trees 1&2
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 题目链接题目描述 给定n个不同元素,求可以构成多少种BST? 思路 这一原创 2018-02-27 11:49:22 · 150 阅读 · 0 评论