摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-04-01 21:20 SunshineAtNoon 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-04-01 17:05 SunshineAtNoon 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321解题:设定一个变量sum存放反转后的答案,每次取输入x的最后一位n,并用sum = sum*10+n更新sum。例如题设的数字123,初始sum为0,过程如下:取末尾的3,sum=3,x=12取末尾的2,sum=32,x=1取末尾的1,sum=321,x=0特别注意x一开始就是0的处理,直接返回0就可以了。代码: 1 class Solution { 2 public: 3 int reverse(int x) {... 阅读全文
posted @ 2014-04-01 11:14 SunshineAtNoon 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2014-04-01 10:58 SunshineAtNoon 阅读(179) 评论(0) 推荐(0) 编辑