Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this subtree by repe...
分类:
其他好文 时间:
2014-08-03 12:49:15
阅读次数:
229
An intuitive 2D DP: dp[i][j] = min(grid[i-1][j-1] + dp[i-1][j], grid[i-1][j-1] + dp[i][j+1])class Solution {public: int minPathSum(vector > &grid) ...
分类:
其他好文 时间:
2014-08-03 07:50:54
阅读次数:
254
题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the....
分类:
编程语言 时间:
2014-08-03 04:40:04
阅读次数:
351
二叉树的深度的概念最值得注意的地方,在于 到"叶子"节点的距离。一般来说,如果直接说“深度”,都是指最大深度,即最远叶子的距离。这里放两道例题,最小深度和最大深度。1. 二叉树的最小深度Given a binary tree, find its minimum depth.The minimum d...
分类:
其他好文 时间:
2014-08-02 23:17:44
阅读次数:
243
The Unique MST
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 20293
Accepted: 7124
Description
Given a connected undirected graph, tell if its minimum spa...
分类:
其他好文 时间:
2014-08-02 20:58:54
阅读次数:
362
题意:二叉树的最小深度注意 1.当root为空的时候直接返回0,因为MIN赋值很大,所以如果不单独预判的话会返回MIN 2.判断树的深度应该到叶子节点,也就是左右子结点都为空的那个结点 3.树的深度的根节点深度为1class Solution {public: void dfs(...
分类:
其他好文 时间:
2014-08-02 20:39:13
阅读次数:
233
Edit DistanceGiven two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You...
分类:
其他好文 时间:
2014-08-02 01:29:22
阅读次数:
309
题目大意:求移动数列中的第一个元素到最后一位时的最少逆序数。(进行n次移动,求移动过程中最少的逆序数)
难点:
一:什么是逆序数? 定义: 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序数。逆序数为偶数的排列称为偶排列;逆序数为奇数的排列称为奇排列。如2431中,21,43,41,31是逆序,逆序数是4...
分类:
其他好文 时间:
2014-08-01 16:07:21
阅读次数:
153
求解最小生成树(Minimum Cost Spanning Tree,以下简写做MST)是图相关的算法中常见的一个,本篇介绍两种求解MST的算法:Prim和Kruskal,然后测试之。
分类:
其他好文 时间:
2014-08-01 06:57:11
阅读次数:
394