随笔分类 - 二叉树
摘要:题目:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of s...
阅读全文
摘要:线段树(segment tree)是一种Binary Search Tree或者叫做ordered binary tree。对于线段树中的每一个非叶子节点[a,b],它的左子树表示的区间为[a,(a+b)/2],右子树表示的区间为[(a+b)/2+1,b]。如下图: ...
阅读全文
摘要:题目:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, ...
阅读全文
摘要:题目:翻转二叉树,例如 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1已知二叉树的节点定义如下:class TreeNode { int val; Tr...
阅读全文
摘要:下面利用一个栈(Stack)分别实现了二叉树的非递归式的前序、中序、后续遍历。代码最后,自定义一个People类,并存储在二叉树中,并依此利用三种遍历方法输出每个People。import java.util.Stack;class TreeNode { TreeNode left, righ...
阅读全文
摘要:下面代码包含了二叉树的建立过程,以及三种遍历方法了递归实现,代码中还利用队列实现了层次遍历。import java.util.LinkedList;import java.util.Queue;class TreeNode { TreeNode left, right; K key; ...
阅读全文
浙公网安备 33010602011771号