上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页
摘要: 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 阅读(790) 评论(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 阅读(1967) 评论(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 阅读(2281) 评论(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 阅读(394) 评论(0) 推荐(0) 编辑
摘要: 题目描述:我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?输入:输入可能包含多个测试样例,对于每个测试案例,输入包括一个整数n(1 2 using namespace std; 3 4 long long res[71]; 5 6 void init() 7 { 8 res[0] = 1; 9 res[1] = 1;10 for (int i = 2; i > n) {21 cout << res[n] << endl;22 }23 return 0;24... 阅读全文
posted @ 2014-04-09 17:22 Eason Liu 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.纯模拟:基本字符IVXLCDM相应的阿拉伯数字表示为1510501005001000相同的数字连写,所表示的数等于这些数字相加得到的数,如:Ⅲ = 3;小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数, 如:Ⅷ = 8;Ⅻ = 12;小的数字,(限于Ⅰ、X 和C)在大的数字的左边,所表示的数等于大数减小数得到的数,如:Ⅳ= 4;Ⅸ= 9;正常使用时,连写的数字重复不得超过三 阅读全文
posted @ 2014-04-09 14:38 Eason Liu 阅读(2232) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-04-09 14:09 Eason Liu 阅读(1894) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页