摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".题解:用栈就行了代码: 1 class Solution {... 阅读全文
posted @ 2014-04-28 16:35 SunshineAtNoon 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2014-04-28 16:14 SunshineAtNoon 阅读(147) 评论(0) 推荐(0) 编辑
摘要: The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie... 阅读全文
posted @ 2014-04-28 15:34 SunshineAtNoon 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 发现自己不写总结真是件很恶劣的事情,好多学的东西没有自己总结都忘记了。所以决定从今天开始,学东西的时候一定跟上总结。我写的东西大多数是自己通俗的总结,不太喜欢写严格的定义或者证明,写了也记不住,欢迎指正。1. High Bias vs. High Variance High Bias:通常是因为模... 阅读全文
posted @ 2014-04-28 00:16 SunshineAtNoon 阅读(861) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?解题:果然不能晚上做题,效率好低。看了讨论才学会的解法。设置一个指针next指向当前访问的节点,如果它不为空,就把它压栈,并且下一个访问它的左节点;如果它为空,就从栈顶一定是它的父... 阅读全文
posted @ 2014-04-03 00:16 SunshineAtNoon 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2014-04-02 15:55 SunshineAtNoon 阅读(200) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解题:开始进入一个误区,跟循环链表搞混了,其实这个环的开头可以不在head这里,例如... 阅读全文
posted @ 2014-04-02 10:37 SunshineAtNoon 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑