摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]像这样列举所有结果的只能DFS了。不过为什么我老是忘记写++low跟--high呢,都死 阅读全文
posted @ 2014-04-10 23:52 Eason Liu 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.给定一个矩阵中,只有0和1,求出这个矩阵的一个最大的子矩阵,其中只包含1.例如011011101001110111101111100000其实这个问题可以转化为Largest Rectangle in Histogram,先将上面的矩阵转化为:011011201003110142102532100000然后对每一行求直方图的最大面积。class S 阅读全文
posted @ 2014-04-10 21:47 Eason Liu 阅读(2622) 评论(0) 推荐(0) 编辑
摘要: 题目描述:给定两个正整数a,b(1 2 using namespace std; 3 4 int gcd(int a, int b) { 5 int m = a > b ? a : b; 6 int n = a > b ? b : a; 7 return n == 0 ? a : gcd(n, m % n); 8 } 9 10 int main() {11 int a, b;12 int max;13 int count;14 int i;15 while (cin >> a >> b) {16 count ... 阅读全文
posted @ 2014-04-10 20:38 Eason Liu 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.no comment. 1 /** 2 * Definition for singly-linked li... 阅读全文
posted @ 2014-04-10 18:01 Eason Liu 阅读(203) 评论(0) 推荐(0) 编辑
摘要: he gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code se 阅读全文
posted @ 2014-04-10 17:32 Eason Liu 阅读(2042) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.纯模拟,规则见:Integer to Roman。 1 class Solution { 2 public: 3 map roman; 4 void init() { 5 roman['I'] = 1; 6 roman['V'] = 5; 7 roman['X'] = 10; 8 roman['L'] = ... 阅读全文
posted @ 2014-04-10 17:18 Eason Liu 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Implementint sqrt(int x).Compute and return the square root ofx.牛顿迭代法, 碉堡了。class Solution {public: int sqrt(int x) { double ans = x; while (abs(ans * ans - x) > 0.0001) { ans = (ans + x / ans) / 2; } return (int)ans; }}; 阅读全文
posted @ 2014-04-10 16:50 Eason Liu 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文
posted @ 2014-04-10 15:52 Eason Liu 阅读(792) 评论(0) 推荐(0) 编辑
摘要: Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2014-04-10 15:15 Eason Liu 阅读(1969) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2014-04-10 14:48 Eason Liu 阅读(148) 评论(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 lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You 阅读全文
posted @ 2014-04-10 14:11 Eason Liu 阅读(2282) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文
posted @ 2014-04-10 13:38 Eason Liu 阅读(397) 评论(0) 推荐(0) 编辑