06 2016 档案

摘要:二叉树的最大深度: 递归的分别获取左右子树的深度,返回较大的深度,每次加1即可。 代码: 二叉树的最小深度: 设置一个深度计数变量 每次获取二叉树的一层结点,依次遍历该层的结点,第一次遇到叶子结点就返回,此时的深度是最小深度。 阅读全文
posted @ 2016-06-08 15:29 沧浪少年 阅读(1844) 评论(0) 推荐(0) 编辑
摘要:题目: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For 阅读全文
posted @ 2016-06-08 15:22 沧浪少年 阅读(195) 评论(0) 推荐(0) 编辑
摘要:题目: Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level 阅读全文
posted @ 2016-06-08 11:24 沧浪少年 阅读(712) 评论(0) 推荐(0) 编辑
摘要:题目: Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to  阅读全文
posted @ 2016-06-07 15:29 沧浪少年 阅读(429) 评论(0) 推荐(0) 编辑
摘要:题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return 阅读全文
posted @ 2016-06-03 22:25 沧浪少年 阅读(909) 评论(0) 推荐(0) 编辑
摘要:题目: 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 阅读全文
posted @ 2016-06-03 17:01 沧浪少年 阅读(576) 评论(0) 推荐(0) 编辑
摘要:题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains 阅读全文
posted @ 2016-06-03 16:26 沧浪少年 阅读(186) 评论(0) 推荐(0) 编辑
摘要:题目要求: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 给出一棵二叉树,其中有两个结点交换了位置,要求找出这两个 阅读全文
posted @ 2016-06-03 15:52 沧浪少年 阅读(214) 评论(0) 推荐(0) 编辑
摘要:树节点定义: 递归建立二叉树: 1、先序遍历 遍历方式:根节点-->左节点-->右节点 递归先序遍历: 非递归遍历: 对于任意一个结点p 1)访问结点p,并将p入栈 2)将p变为p的左孩子结点,如果p的不为空,循环至 1); 否则弹出当前栈顶使用p接收,将p变为p的右孩子结点; 3)当p结点为nul 阅读全文
posted @ 2016-06-02 18:01 沧浪少年 阅读(398) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示