二叉查找树(Binary Search Tree),(又:二叉搜索树,二叉排序树)它或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉排序树。以下是楼 ...
分类:
编程语言 时间:
2018-10-01 23:15:38
阅读次数:
160
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, or ...
分类:
其他好文 时间:
2018-10-01 22:10:37
阅读次数:
196
A. Maximal Binary Matrix 解法:暴力模拟+贪心 #include<bits/stdc++.h> using namespace std; int a[110][110]; int main(){ int n,k,cmp,f=0;scanf("%d%d",&n,&k); if( ...
分类:
其他好文 时间:
2018-10-01 21:38:20
阅读次数:
175
一、题目 1、审题 2、分析 给出一颗二叉树,求最小高度(根节点到叶节点的最短距离)。 二、解答 1、思路: 方法一、 采用 BFS 层次遍历的方法进行遍历二叉树。同时,若出现叶子节点,则返回当前高度。 方法二、 采用递归。 另外 ...
分类:
其他好文 时间:
2018-10-01 17:57:34
阅读次数:
160
一、题目 1、审题 2、分析 给出一棵二叉树,判断其是否是一棵二叉平衡树。 二、解答 1、思路: 方法一、 采用递归; 每次获取 root 结点的左子树、右子树的高度,比较高度差是否小于等于 1; 同时判断左子树、右子树是否也是二叉平衡树。 方法二、 采用深度优先遍历的方式获取深度,并且获取时比较该 ...
分类:
其他好文 时间:
2018-10-01 17:13:19
阅读次数:
180
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes ...
分类:
其他好文 时间:
2018-10-01 15:32:22
阅读次数:
196
一、题目 1、审题 2、分析 给出一个有序的不重复的整形数组,组成一个二路平衡二叉树(左右子树高度差不超过1)。 二、解答 1、思路: 方法一、 采用递归的方式。(像二分查找) ①、为了保持平衡,查找数组的下标中间的数 nums[mid],作为 root; ②、(0, mid - 1) 作为 roo ...
分类:
其他好文 时间:
2018-10-01 12:54:08
阅读次数:
166
一、题目 1、审题 2、分析 给出一个二叉树,从下往上输出每一层的节点值。 二、解答 1、思路: 方法一、BFS 利用一个队列进行层次遍历,同时 List 进行插入时,利用 add(index, val) 方法, index 指定插入的 List 的下标。 方法二、DFS 采用递归进行层次遍历,从上 ...
分类:
其他好文 时间:
2018-10-01 11:56:09
阅读次数:
131
题目 Given two binary strings, return their sum (also a binary string). The input strings are both non empty and contains only characters 1 or 0. Exampl ...
分类:
其他好文 时间:
2018-10-01 11:52:46
阅读次数:
104
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means t ...
分类:
其他好文 时间:
2018-10-01 11:52:01
阅读次数:
141