摘要: 1 class Solution { 2 public: 3 bool searchMatrix(vector > &matrix, int target) { 4 int rows, cols; 5 if (!(rows = matrix.size()) || !(cols = matrix[0].size())) return false; 6 int ridx, cur, first = -1, last = rows; 7 while (first + 1 target) {13 ... 阅读全文
posted @ 2014-04-10 20:30 卖程序的小歪 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 if (n <= 2) return n; 5 int wpos = 1; 6 int dups = 0; 7 int cur, last = A[0]; 8 9 for (int i=1; i<n; i++) {10 cur = A[i];11 dups = (cur == last) ? dup... 阅读全文
posted @ 2014-04-10 19:33 卖程序的小歪 阅读(128) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: void reverseWords(string &s) { int len = s.length(); reverse(s.begin(), s.end()); int wpos = 0; ... 阅读全文
posted @ 2014-04-04 01:02 卖程序的小歪 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 string longestCommonPrefix(vector &strs) { 4 if (strs.size() == 0) return ""; 5 string commstr = s... 阅读全文
posted @ 2014-04-03 00:44 卖程序的小歪 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 1 class LRUCache{ 2 private: 3 int max_size; 4 unordered_map >::iterator> hash; 5 list > lru_stack; 6 public: 7 LRUCache(int capacity... 阅读全文
posted @ 2014-04-02 22:29 卖程序的小歪 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 bool isSymmetric(TreeNode *root) { 4 if (root == NULL) return true; 5 return dfs(root->left, root-... 阅读全文
posted @ 2014-04-01 16:05 卖程序的小歪 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int minCut(string s) { 4 int len = s.length(); 5 int* p_dp = new int[len + 1]; 6 char* s_dp = new char[len * len]; 7 int* mm = new int[len + 1]; 8 mm[0] = 0; 9 memset(s_dp, -1, len * len);10 memset(p_dp, 0,... 阅读全文
posted @ 2014-03-27 01:10 卖程序的小歪 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 vector > partition(string s) { 4 int len = s.length(); 5 vector >* memo = new vector >[len + 1]; 6 vector > ret; 7 8 for (int i=1; i >& cur = memo[i];11 12 for (int j=i-1; j>=0; j--) {13 ... 阅读全文
posted @ 2014-03-26 20:48 卖程序的小歪 阅读(201) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int removeDuplicates(int A[], int n) { if (n == 0) return 0; int *rpos = A, *wpos = A + 1, *end = A + n; int cur; int pre = *(rpos++); while (rpos != end) { cur = *(rpos++); if (pre == cur) continue; *(wpos++) = pre = cur; } retur... 阅读全文
posted @ 2014-03-26 00:09 卖程序的小歪 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 string addBinary(string a, string b) { 4 string res; 5 int carry = 0, s = 0; 6 int apos = a.length() - 1; 7 int bpos = b.length() - 1; 8 int astp = 0, bstp = 0; 9 // skip leading zero(s)10 for (; astp = astp,... 阅读全文
posted @ 2014-03-25 00:48 卖程序的小歪 阅读(149) 评论(0) 推荐(0) 编辑