摘要: Logic is simple, but careful with the details. 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left;... 阅读全文
posted @ 2015-03-19 10:09 keepshuatishuati 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Two methods:1. Use extra memory: 1 class Solution { 2 public: 3 int firstMissingPositive(int A[], int n) { 4 unordered_set sets; 5 ... 阅读全文
posted @ 2015-03-19 10:03 keepshuatishuati 阅读(153) 评论(0) 推荐(0) 编辑
摘要: The ticky part for this question is :mid == 0 num[mid] num[mid] > num[mid+1] end = mid - 1;mid = l num[mid] 0 && num[mid] > num[mid - 1] end = mid... 阅读全文
posted @ 2015-03-19 09:55 keepshuatishuati 阅读(109) 评论(0) 推荐(0) 编辑
摘要: lazy solutions..... Just skip the duplicates. Then worse case of time is O(n). 1 class Solution { 2 public: 3 int findMin(vector &num) { 4 ... 阅读全文
posted @ 2015-03-19 09:36 keepshuatishuati 阅读(90) 评论(0) 推荐(0) 编辑
摘要: Be carefully with one element and two element sitution.1. Since mid = (start + end) / 2 is alway shifting to the left. So when we do comparision, not ... 阅读全文
posted @ 2015-03-19 09:30 keepshuatishuati 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Think about that.. n! = n * (n-1) * (n-2) ..... *1Zeros happened when each of them can be divided by 10. And 10 = 2 * 5. 2 is much more than 5 in the ... 阅读全文
posted @ 2015-03-19 09:16 keepshuatishuati 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Only trick is the 'Z'. Because when the number % 26 == 0, means there is a 'Z'. But when you n/=26, there is an extra 1 added to the n. EX:27 % 26 = 1... 阅读全文
posted @ 2015-03-19 09:11 keepshuatishuati 阅读(127) 评论(0) 推荐(0) 编辑
摘要: No tricks. 1 class Solution { 2 public: 3 int titleToNumber(string s) { 4 int result = 0, len = s.size(); 5 for (int i = 0; i < le... 阅读全文
posted @ 2015-03-19 09:03 keepshuatishuati 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Just use a stack to record the numbers. And evey time you encounter a operator, pop two numbers, calucate it and push it back.Do not disorder the numb... 阅读全文
posted @ 2015-03-19 08:58 keepshuatishuati 阅读(159) 评论(0) 推荐(0) 编辑
摘要: Still a DP problem.The transition function is not hard to get:1. When s[i-1] == t[j-1], which means we dont have to do any thing to handle the current... 阅读全文
posted @ 2015-03-19 08:49 keepshuatishuati 阅读(137) 评论(0) 推荐(0) 编辑