What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given ...
分类:
其他好文 时间:
2014-07-22 08:37:34
阅读次数:
289
class Solution {public: int trap(int A[], int n) { if (n peaks; vector peaks_tmp; int last_idx = 0; bool increasing = ...
分类:
移动开发 时间:
2014-07-21 09:04:11
阅读次数:
259
class Solution {private: const static char* pattern[]; const static char* roman[]; unordered_map a2i;public: int romanToInt(string s) { ...
分类:
其他好文 时间:
2014-07-20 22:27:18
阅读次数:
196
It is often useful to swap the values of two variables. With conventional assignments, you have to use a temporary variable. This solution is cumberso...
分类:
其他好文 时间:
2014-07-19 18:32:06
阅读次数:
243
Implementint sqrt(int x).Compute and return the square root ofx.题解:二分的方法,从0,1,2.....x搜索sqrt(x)的值。代码如下: 1 public class Solution { 2 public int sqrt...
分类:
其他好文 时间:
2014-07-19 17:37:22
阅读次数:
196
class Solution {public: vector generateParenthesis(int n) { string str; vector res; dfs(n, 0, 0, str, res); return res;...
分类:
其他好文 时间:
2014-07-19 15:28:21
阅读次数:
207
class Solution {public: int maxSubArray(int A[], int n) { int cur_sum = 0; int max_sum = INT_MIN; for (int i=0; i max_...
分类:
其他好文 时间:
2014-07-19 15:18:15
阅读次数:
160
class Solution {public: vector > subsetsWithDup(vector &S) { int len = S.size(); vector > res; vector subset; if (len ...
分类:
其他好文 时间:
2014-07-19 11:35:37
阅读次数:
175
class Solution {public: void rotate(vector > &matrix) { int n = matrix.size(); int end = n / 2; for (int i=0; i<end; i++) { ...
分类:
其他好文 时间:
2014-07-19 11:19:11
阅读次数:
162
class Solution {public: bool isPalindrome(int x) { if (x < 0) return false; int pow = 1; int t = x; int cnt = 1; ...
分类:
其他好文 时间:
2014-07-19 08:35:19
阅读次数:
190