摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2014-04-02 22:55 Eason Liu 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated number may be chosen fromCunlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak 阅读全文
posted @ 2014-04-02 21:29 Eason Liu 阅读(128) 评论(0) 推荐(0) 编辑
摘要: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).好难啊,总是会有各种边界问题。想法如下:最后从medianof two sorted arrays中看到了一种非常好的方法。原文用英文进行解释,在此我们将其翻译成汉语。该方法的核心是将原问题转变成一个寻找第k小数的问题(假设两个原序列升序排列),这样中位数实际上是第(m+n 阅读全文
posted @ 2014-04-02 18:48 Eason Liu 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 题目描述:又到毕业季,很多大公司来学校招聘,招聘会分散在不同时间段,小明想知道自己最多能完整的参加多少个招聘会(参加一个招聘会的时候不能中断或离开)。输入:第一行n,有n个招聘会,接下来n行每行两个整数表示起止时间,由从招聘会第一天0点开始的小时数表示。n 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct data { 8 int st; 9 int ed;10 };11 12 bool cmp(const data &a, const data &b) {13 return ... 阅读全文
posted @ 2014-04-02 01:27 Eason Liu 阅读(256) 评论(0) 推荐(0) 编辑
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.没啥好说的。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(... 阅读全文
posted @ 2014-04-02 00:18 Eason Liu 阅读(157) 评论(0) 推荐(0) 编辑