摘要: Sort a linked list using insertion sort. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *nex... 阅读全文
posted @ 2014-06-09 22:49 小菜刷题史 阅读(400) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.单向链表排序O(nlogn),Mergesort可以实现。 1 /** 2 * Definition for singly-linked list. 3 * st... 阅读全文
posted @ 2014-06-09 21:27 小菜刷题史 阅读(132) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.每次固定一个点,然后遍历所有其它点,记录每种斜率出现的次数。需要考虑两种特殊情况:斜率不存在和点与固定点重... 阅读全文
posted @ 2014-06-09 20:51 小菜刷题史 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 问题描述:给定一个迷宫和一个起点一个终点,求起点到终点的最短路径长度。Sample Input(说明:5行5列的迷宫,‘#’为墙,‘.’为路,起点为(0,3), 终点为(4,4))Sample Output11(若不可达输出-1)解答:用BFS的方法,借助一个队列实现。 1 #include 2 #... 阅读全文
posted @ 2014-06-09 19:36 小菜刷题史 阅读(473) 评论(0) 推荐(0) 编辑
摘要: 问题描述:Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with t... 阅读全文
posted @ 2014-06-09 17:00 小菜刷题史 阅读(221) 评论(0) 推荐(0) 编辑