摘要: Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].解题思路:先按左端点排序,然... 阅读全文
posted @ 2014-12-10 12:14 ElephantKing 阅读(91) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ... 阅读全文
posted @ 2014-12-10 00:58 ElephantKing 阅读(85) 评论(0) 推荐(0) 编辑
摘要: A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2014-12-08 20:22 ElephantKing 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 对于传统的二分查找,若能找到,则返回target的下标,若找不到则返回-1后,退出函数。齐代码比较简单,如下:int bSearch(vec vec, int start,int end,int target){ int first = start,last = end,mid; whi... 阅读全文
posted @ 2014-12-06 19:29 ElephantKing 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol... 阅读全文
posted @ 2014-12-06 15:57 ElephantKing 阅读(95) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2014-12-05 14:24 ElephantKing 阅读(87) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int min(int a, int b) { return a>b?b:a; } int getMin(vector > grid, int m, int n) { int current =... 阅读全文
posted @ 2014-12-05 14:20 ElephantKing 阅读(132) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ... 阅读全文
posted @ 2014-12-04 20:10 ElephantKing 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2014-12-03 19:46 ElephantKing 阅读(133) 评论(1) 推荐(0) 编辑
摘要: Pascal's Triangle IIGiven an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your alg... 阅读全文
posted @ 2014-12-02 20:28 ElephantKing 阅读(92) 评论(0) 推荐(0) 编辑