最新文章列表

Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total ...
KickCode 评论(0) 有512人浏览 2016-02-11 03:24

Populating Next Right Pointers in Each Node

Given a binary tree     struct TreeLinkNode {       TreeLinkNode *left;       TreeLinkNode *right;       TreeLinkNode *next;     } Populate each next pointer to point to its next right node. If there ...
KickCode 评论(0) 有721人浏览 2016-02-10 01:51

Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place. For example, Given          1         / \        2   5       /  \    \      3   4   6 The flattened tree should look like:    1     \      2 ...
KickCode 评论(0) 有341人浏览 2016-02-09 05:20

Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22,               5              / \           ...
KickCode 评论(0) 有823人浏览 2016-02-09 04:56

Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = ...
KickCode 评论(0) 有246人浏览 2016-02-09 04:34

Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 求一棵树的最短路径,同样用递归来解决。注意的是如果遇到一个节点只有一个孩子,这 ...
KickCode 评论(0) 有742人浏览 2016-02-09 04:16

Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 给定一个单向有序的列表,将它转换成一颗平衡二叉搜索树。我们采用快慢指针,然后确定链表中的中间节点,将中间作为当前子树的根节点,然后将链表分为两段,递归完成。代码如下: /** ...
KickCode 评论(0) 有330人浏览 2016-02-08 05:30

Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 用后序遍历序列来确定根节点的位置,然后在中序遍历中确定左右子树,递归完成树的构造。代码如下: /** * Def ...
KickCode 评论(0) 有810人浏览 2016-02-08 05:02

Construct Binary Tree from Preorder and Inorder Traversal

iven preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 给定一棵树的中序遍历和前序遍历,构造出这棵树。我们可以通过前序遍历序列的第一个元素判断出每个子树的根节点,然后在中序遍历序列 ...
KickCode 评论(0) 有767人浏览 2016-02-08 04:29

Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7},     ...
KickCode 评论(0) 有375人浏览 2016-02-07 05:16

Same Tree

Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 给定两颗二叉树,判断这两颗树是 ...
KickCode 评论(0) 有1097人浏览 2016-02-06 12:35

Unique Binary Search Trees

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.    1           3     3      2       1      \   ...
KickCode 评论(0) 有353人浏览 2016-02-06 11:12

Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3},    1     \      2     /    3 return [1,3,2]. 中序遍历一棵树,我们可以采用递归,也可以用迭代,用迭代的时候借助堆栈来完成。 1 ...
KickCode 评论(0) 有376人浏览 2016-02-06 10:46

【数据结构】【查找】二叉排序树

       使用二叉排序树查找效率也非常高,当然有更稳定的二叉平衡树,但是实现起来比较困难,所以这里只实现了二叉排序树;二叉排序树的特点如下: 左子树中的所有节点值都小于父节点值 右子树中的所有节点值都大于父节点值 所有节点不允许出现重复,否则会破坏二叉排序树的数据结构 二叉排序树的中序遍历的结果就是所有元素的排序结果 二叉排序树是二叉树 所以,使用二叉排序树不仅仅能够实现快速 ...
狂盗一枝梅 评论(0) 有694人浏览 2016-01-22 13:25

【数据结构】【二叉树】二叉树的创建和遍历

二叉树的创建有两种方式,一种是递归方式创建,另外一种是非递归方式创建,其中后者比较难,这里使用递归方式创建二叉树。 要求:使用前序序列的方式输入若干个字符,如" abc,,de,g,,f,,, ",其中,','表示是空节点,根据该字符序列输出前序遍历字符串,中续遍历字符串,后序遍历字符串。   分析问题,如果使用C语言比较方便实现,使用java稍微麻烦一点,需要手动结 ...
狂盗一枝梅 评论(0) 有458人浏览 2016-01-21 23:19

二叉树BFS变形题目总结

二叉树广度优先遍历我们采用队列来实现,这里列举三道leetcode中有关二叉树BFS的题目,总的思想是一样的,题目要求的输出不同,我们需要根据不同的要求来编写,考察我们对于二叉树搜索的基本思想掌握以及java基础的掌握。 1,Binary Tree Level Order Traversal 给定一颗二叉树,用广度优先搜索遍历所有节点,并输出结果。 例如:     3    / \   9  20 ...
KickCode 评论(0) 有733人浏览 2016-01-06 11:54

哈弗曼算法实现压缩和解压

//这是我一个学长的,我看了好久才明白,给大家分享,这里的代码只是一个压缩方法的,还有 //一些类已经上传(测试类,结构类都在文件里面),需要可以下载,这个算法没有用递归遍历整个文件夹,所以之只能压缩 //一个文件,下面是主要压缩步骤: //整个压缩文件的内容:(写入顺序) * 1.将原文件大小写入文件 dos.writeInt(fileSize); * 2.将码表的大小写入文件 d ...
qq_24665727 评论(0) 有1449人浏览 2015-12-29 21:14

Binary Tree的题目总结(三)

这篇文章主要列举数组或者链表如何转换为二叉树。 1,Convert Sorted Array to Binary Search Tree 将一个有序数组变为二叉平衡树。 因为数组有序,我们通过二分法,依次将数组元素变为数节点,代码如下: /** * Definition for a binary tree node. * public class TreeNode { * ...
KickCode 评论(0) 有418人浏览 2015-12-16 08:15

Binary Tree的题目总结(一)

与数组和链表相比,树的题目比它们要难一些,我们往往通过递归来处理树的题目,下面是对leetcode有关树操作的几道题目,包括找出树的所有路径,计算完全二叉树节点个数,二叉搜索树的最近公共祖先,普通二叉树的最近公共祖先。 1,Binary Tree Paths 给定一个二叉树,输出所有根节点到叶子节点的路径。 用深度优先遍历(DFS),依次保留搜索过的节点。代码如下: /** * Defi ...
KickCode 评论(0) 有963人浏览 2015-12-16 03:40

二叉树的深搜和广搜

二叉树是计算机中一个重要的数据结构,在这里主要谈一下二叉树的深度优先搜索(DFS)和广度优先搜索(BFS)。 所谓DFS,就是沿着树的深度一直往下,一直到达一个叶子节点,然后再返回遍历剩余的节点。根据树的性质,树结构不存在环,因此遍历的时候不需要标记。如果在遍历一个图的时候,因为图中有环的存在,因此需要标记访问过的节点,以防止程序进入死循环。言归正传,树的DFS有三种方式,分别为:前序遍历,中序遍 ...
KickCode 评论(0) 有1075人浏览 2015-12-02 12:40

最近博客热门TAG

Java(141744) C(73651) C++(68608) SQL(64571) C#(59609) XML(59133) HTML(59043) JavaScript(54919) .net(54785) Web(54514) 工作(54118) Linux(50905) Oracle(49875) 应用服务器(43289) Spring(40812) 编程(39454) Windows(39381) JSP(37542) MySQL(37267) 数据结构(36424)

博客人气排行榜

    博客电子书下载排行

      >>浏览更多下载

      相关资讯

      相关讨论

      Global site tag (gtag.js) - Google Analytics