摘要:
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'] = ... 阅读全文
摘要:
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; }}; 阅读全文
摘要:
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 阅读全文
摘要:
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 / / \ ... 阅读全文
摘要:
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
摘要:
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 阅读全文
摘要:
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... 阅读全文