Brute Force: 1 class Solution { 2 public: 3 int strStr(char *haystack, char *needle) { 4 if (!haystack) return -1; 5 if (!needle) ...
分类:
其他好文 时间:
2015-03-20 01:13:34
阅读次数:
110
Not quite hard. Just remember initialize index to 0. Because if you initialize it as -1 and all the gas satisfy the cost, it will return -1.Actually, ...
分类:
其他好文 时间:
2015-03-20 01:11:41
阅读次数:
210
i ^ (i >> 1), that's the general format 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 vector result; 5 for (int i = 0;...
分类:
其他好文 时间:
2015-03-20 01:09:59
阅读次数:
140
Notes:1. When numerator is 0, return "0". Check this corner case, because 0 / -5 will return -0.2. Use long long int for divd and divs, mainly for div...
分类:
其他好文 时间:
2015-03-19 23:44:46
阅读次数:
162
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 ...
分类:
其他好文 时间:
2015-03-19 10:07:57
阅读次数:
118
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...
分类:
其他好文 时间:
2015-03-19 10:05:24
阅读次数:
256
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 ...
分类:
其他好文 时间:
2015-03-19 10:01:34
阅读次数:
141
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 ...
分类:
其他好文 时间:
2015-03-19 10:01:03
阅读次数:
140
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...
分类:
其他好文 时间:
2015-03-19 09:59:59
阅读次数:
113
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...
分类:
其他好文 时间:
2015-03-19 09:59:13
阅读次数:
110