Iterative: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : ...
分类:
其他好文 时间:
2015-03-21 08:37:15
阅读次数:
117
Notes:1. When check left shifting, do not use continue, but break it!!! Otherwise, you wil fall into infinite loop2. Initialize the map with T, not S!...
1 class Solution { 2 public: 3 string getRange(int start, int end) { 4 ostringstream oss; 5 if (start == end) { 6 oss...
分类:
其他好文 时间:
2015-03-21 08:36:43
阅读次数:
154
Simple DP, but notes:1. initialize the array not only for dp[i] += dp[i-1], but also dp[i] += dp[i-1] + grid[i][0];2. Clear that we are using one dime...
分类:
其他好文 时间:
2015-03-21 08:35:36
阅读次数:
115
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i...
分类:
其他好文 时间:
2015-03-21 08:35:28
阅读次数:
123
Use two stacks :class MinStack {private: stack s, minS;public: void push(int x) { if (minS.empty() || x s;public: void push(int x) { ...
分类:
其他好文 时间:
2015-03-21 08:34:04
阅读次数:
124
1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * ...
分类:
其他好文 时间:
2015-03-21 07:32:56
阅读次数:
121
Note:Since it merged from end, so1. tmp1, tmp2 = INT_MIN2. tmp1 > tmp2 1 class Solution { 2 public: 3 void merge(int A[], int m, int B[], int n) {...
分类:
其他好文 时间:
2015-03-21 07:32:13
阅读次数:
117
Use merge two looply merge the from the queue. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNod...
分类:
其他好文 时间:
2015-03-21 07:30:23
阅读次数:
126
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i...
分类:
其他好文 时间:
2015-03-21 06:22:17
阅读次数:
111