本月博客排行
-
第1名
龙儿筝 -
第2名
lerf -
第3名
fantaxy025025 - johnsmith9th
- xiangjie88
- zysnba
年度博客排行
-
第1名
青否云后端云 -
第2名
宏天软件 -
第3名
gashero - wy_19921005
- vipbooks
- benladeng5225
- e_e
- wallimn
- javashop
- ranbuijj
- fantaxy025025
- jickcai
- gengyun12
- zw7534313
- qepwqnp
- 解宜然
- ssydxa219
- zysnba
- sam123456gz
- sichunli_030
- arpenker
- tanling8334
- gaojingsong
- kaizi1992
- xpenxpen
- 龙儿筝
- jh108020
- wiseboyloves
- ganxueyun
- xyuma
- xiangjie88
- wangchen.ily
- Jameslyy
- luxurioust
- lemonhandsome
- mengjichen
- jbosscn
- zxq_2017
- lzyfn123
- nychen2000
- forestqqqq
- wjianwei666
- ajinn
- zhanjia
- Xeden
- hanbaohong
- java-007
- 喧嚣求静
- mwhgJava
- kingwell.leng
最新文章列表
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 ...
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 ...
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 ...
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
/ \
...
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.
给定一个单向有序的列表,将它转换成一颗平衡二叉搜索树。我们采用快慢指针,然后确定链表中的中间节点,将中间作为当前子树的根节点,然后将链表分为两段,递归完成。代码如下:
/**
...
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 ...
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.
给定一棵树的中序遍历和前序遍历,构造出这棵树。我们可以通过前序遍历序列的第一个元素判断出每个子树的根节点,然后在中序遍历序列 ...
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
\ ...
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 ...
哈弗曼算法实现压缩和解压
//这是我一个学长的,我看了好久才明白,给大家分享,这里的代码只是一个压缩方法的,还有
//一些类已经上传(测试类,结构类都在文件里面),需要可以下载,这个算法没有用递归遍历整个文件夹,所以之只能压缩
//一个文件,下面是主要压缩步骤:
//整个压缩文件的内容:(写入顺序)
* 1.将原文件大小写入文件 dos.writeInt(fileSize);
* 2.将码表的大小写入文件 d ...
Binary Tree的题目总结(三)
这篇文章主要列举数组或者链表如何转换为二叉树。
1,Convert Sorted Array to Binary Search Tree
将一个有序数组变为二叉平衡树。
因为数组有序,我们通过二分法,依次将数组元素变为数节点,代码如下:
/**
* Definition for a binary tree node.
* public class TreeNode {
* ...