Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题解:开始想到的方法比较偷懒,直接遍历一遍数组,把每个ListNode对应的值放到...
分类:
其他好文 时间:
2014-07-22 22:45:13
阅读次数:
271
PrerequisitesSharePoint Office 365 site: You can select the developer template to create your site collection. If you haven’t O365 account, you can go...
分类:
移动开发 时间:
2014-07-22 00:36:36
阅读次数:
384
Insertion Sort ListSort a linked list using insertion sort.算法思路:最基本的插入排序,时间复杂度O(n*n),空间复杂度O(1)代码: 1 public class Solution { 2 public ListNode inse...
分类:
其他好文 时间:
2014-07-22 00:23:34
阅读次数:
204
第一道正儿八经的差分约束题有排成一列的n个点,首先告诉你每个点的值最多是多少(最少显然要大于0),然后告诉你m段i,j,k,表示第i个点到第j个点的值的和至少有k,问你总和至少为多少。要注意的是,告诉你的所有关系式都不要忘记建边,一开始漏了大于0的条件调半天o(╯□╰)o不等式的形式是a-b 2 #...
分类:
其他好文 时间:
2014-07-22 00:20:34
阅读次数:
178
Reorder ListGiven a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' val...
分类:
其他好文 时间:
2014-07-22 00:16:36
阅读次数:
230
Sort ListSort a linked list inO(nlogn) time using constant space complexity.算法思想:时间复杂度为O(nlogn)的排序算法,有快排、归并、堆排序,快排需要往前遍历,因此不适合单链表,堆排序可以,但是需要O(n)的空间,因此...
分类:
其他好文 时间:
2014-07-22 00:03:35
阅读次数:
187
1.Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
2.Given a singly linked list where elements are sorted in ascending order, convert it to a heig...
分类:
其他好文 时间:
2014-07-21 23:45:53
阅读次数:
264
差分约束(最短路)
不等式用最短路来求。问题是好难找约束条件——建立不等式。
题意问最少有多少兵。即建立好各点的约束条件,求0~N 的最短路。
有负环得判断入队次数。
反正还没多大理解差分约束,Hurry up!
#include
#include
#include
#include
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2014-07-21 16:31:02
阅读次数:
198
Partition ListGiven a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should pres...
分类:
其他好文 时间:
2014-07-21 08:28:54
阅读次数:
230
关于二叉树的遍历有很多的方法, 下面介绍两个经典的遍历算法: BFS和DFS。一个是深度优先遍历, 一个是广度有优先遍历。 这两种遍历算法均属于盲目的遍历算法, 一般而言, 启发式的遍历搜索算法比较好一些。 。 关于各种遍历算法的对比, 将会在后面逐一提及。 这里不在赘述。
由于树是一个非线性的数据结构, 显然不能像linked list , 或者Array那样通过从头像最末尾移动去实现遍历每一...
分类:
编程语言 时间:
2014-07-20 23:14:21
阅读次数:
387