03 2014 档案

摘要: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 卖程序的小歪 阅读(175) 评论(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 卖程序的小歪 阅读(208) 评论(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 卖程序的小歪 阅读(92) 评论(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 卖程序的小歪 阅读(159) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public: 3 int numTrees(int n) { 4 return dfs(1, n); 5 } 6 7 int dfs(int start, int end) { 8 if ... 阅读全文
posted @ 2014-03-24 23:53 卖程序的小歪 阅读(167) 评论(0) 推荐(0)
摘要:class Solution {public: // verbose one vector insert(vector &intervals, Interval newInterval) { vector ret; int ns = newInterval.s... 阅读全文
posted @ 2014-03-24 18:50 卖程序的小歪 阅读(202) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool hasPathSum(TreeNode *root, int sum) { return dfs(root, 0, sum); } bool d... 阅读全文
posted @ 2014-03-24 16:06 卖程序的小歪 阅读(158) 评论(0) 推荐(0)
摘要:class Solution {public: vector findSubstring(string S, vector &L) { vector res; unordered_map stat; unordered_map run; int len = S.size(); int num = L.size(); int per = 0; if (num == 0 || !(per = L[0].size())) return res; int part= num * per; if (part > len) return res; ... 阅读全文
posted @ 2014-03-22 14:41 卖程序的小歪 阅读(337) 评论(0) 推荐(0)
摘要:class Solution {public: int maxPathSum(TreeNode *root) { int s, m; dfs(root, s, m); return (m > s) ? m : s; } void d... 阅读全文
posted @ 2014-03-22 01:26 卖程序的小歪 阅读(272) 评论(0) 推荐(0)
摘要:引用可以简化原来使用指针的代码,至少看起来舒服点,不过今天发现个问题,先来看一段代码#include #include #include using namespace std;int main() { vector stack; stack.push_back(1); int& rx = stack[0]; int vx = stack[0]; int vy = rx; cout >::operator[] (0FC1276h) 00FC649F mov dword ptr [rx],eax i... 阅读全文
posted @ 2014-03-21 22:04 卖程序的小歪 阅读(252) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector preorderTraversal(TreeNode *root) { vector res; if (root == NULL) return ... 阅读全文
posted @ 2014-03-21 14:28 卖程序的小歪 阅读(140) 评论(0) 推荐(0)
摘要:class Solution {public: vector inorderTraversal(TreeNode *root) { vector res; if (root == NULL) return res; vector > stack; ... 阅读全文
posted @ 2014-03-21 12:53 卖程序的小歪 阅读(228) 评论(0) 推荐(0)
摘要:class Solution {public: vector twoSum(vector &numbers, int target) { vector ret; vector > nums; for (int i=0; i target) { ... 阅读全文
posted @ 2014-03-21 02:41 卖程序的小歪 阅读(209) 评论(0) 推荐(0)
摘要:class Solution {public: int minimumTotal(vector > &triangle) { if (!triangle.size() || !triangle[0].size()) return 0; int row... 阅读全文
posted @ 2014-03-21 02:06 卖程序的小歪 阅读(132) 评论(0) 推荐(0)
摘要:typedef struct tagCharUsed { int i; int j; bool used; tagCharUsed(int _i, int _j, bool _used = false): i(_i), j(_j), used(_used){};} CharU... 阅读全文
posted @ 2014-03-20 15:23 卖程序的小歪 阅读(211) 评论(0) 推荐(0)
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2014-03-19 23:57 卖程序的小歪 阅读(173) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(... 阅读全文
posted @ 2014-03-19 01:23 卖程序的小歪 阅读(161) 评论(0) 推荐(0)
摘要:class Solution {public: int minDepth(TreeNode *root) { if (root == NULL) return 0; int min_depth = INT_MAX; dfs(root, 0, min_d... 阅读全文
posted @ 2014-03-18 16:15 卖程序的小歪 阅读(180) 评论(0) 推荐(0)
摘要:class Solution {public: int minDistance(string word1, string word2) { const int cols = word1.length() + 1; const int rows = word2.len... 阅读全文
posted @ 2014-03-18 15:36 卖程序的小歪 阅读(244) 评论(0) 推荐(0)
摘要:class Solution {public: vector > combinationSum2(vector &num, int target) { sort(num.begin(), num.end()); vector > tmp; vector sel; dfs(num, 0, target, sel, tmp); return tmp; } void dfs(vector &num, int pos, int target, vector& sel, vector >& r... 阅读全文
posted @ 2014-03-17 21:10 卖程序的小歪 阅读(180) 评论(0) 推荐(0)
摘要:class Solution {public: vector > combinationSum(vector &candidates, int target) { sort(candidates.begin(), candidates.end()); candidates.erase(unique(candidates.begin(), candidates.end()), candidates.end()); vector > tmp; vector sel; dfs(... 阅读全文
posted @ 2014-03-17 19:54 卖程序的小歪 阅读(198) 评论(0) 推荐(0)
摘要:class Solution {public: int lengthOfLongestSubstring(string s) { int len = s.length(); if (len mlen) mlen = clen; q++; ... 阅读全文
posted @ 2014-03-15 12:41 卖程序的小歪 阅读(159) 评论(0) 推荐(0)
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2014-03-15 10:35 卖程序的小歪 阅读(177) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL), random(NULL) {} * }; */class Solution {public: RandomListNode *copyRandomList(RandomListNode *head) { ... 阅读全文
posted @ 2014-03-14 21:10 卖程序的小歪 阅读(334) 评论(0) 推荐(0)
摘要:class Solution {public: int uniquePathsWithObstacles(vector > &obstacleGrid) { vector >& dp = obstacleGrid; if (dp.empty() || dp[0].e... 阅读全文
posted @ 2014-03-14 19:56 卖程序的小歪 阅读(165) 评论(0) 推荐(0)
摘要:class Solution {public: int uniquePaths(int m, int n) { int (*dp)[101] = new int[101][101]; for (int i=0;i<101;i++) dp[0][i] = 0; ... 阅读全文
posted @ 2014-03-14 16:58 卖程序的小歪 阅读(159) 评论(0) 推荐(0)
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded messag... 阅读全文
posted @ 2014-03-13 22:22 卖程序的小歪 阅读(198) 评论(0) 推荐(0)
摘要:class Solution {private: int row[9]; int col[9]; int blk[9]; public: void solveSudoku(vector > &board) { if (board.empty() || board[0].empty()) return; initBits(board); dfs(board, 0, 0); } bool dfs(vector >& board, int ridx, int cidx) { ... 阅读全文
posted @ 2014-03-13 16:24 卖程序的小歪 阅读(221) 评论(0) 推荐(0)
摘要:class Solution {private: // only used by _isValidSudoku int row[9]; int col[9]; int blk[9];public: bool _isValidSudoku(vector >& board) { if (board.empty()) return true; memset(row, 0, sizeof(row)); memset(col, 0, sizeof(col)); memset(blk, 0, sizeof(blk)); ... 阅读全文
posted @ 2014-03-12 21:34 卖程序的小歪 阅读(161) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public: 3 void solve(vector > &board) { 4 if (board.size() == 0) return; 5 int my = board.size() - 1; 6 int mx = board[0].size() -1; 7 // top border 8 for (int i=0; i >& board, int mx, int my, int _x, int _y, char oc, char nc) {40 ... 阅读全文
posted @ 2014-03-11 21:37 卖程序的小歪 阅读(202) 评论(0) 推荐(0)
摘要:int sqrt(int x) { int lo = 0; int hi = x; int m = 0; double mul = 0; for (;;) { m = (lo + hi) / 2; if (lo > hi) break; mul = 1.0 * m * m; if (mul > x) { hi = m - 1; } else if (mul == x) { ... 阅读全文
posted @ 2014-03-11 16:17 卖程序的小歪 阅读(210) 评论(0) 推荐(0)
摘要:1 double pow(double x, int n) { 2 if (n == 0) return 1; 3 unsigned int k = 0; 4 if (n >=1;14 }15 return ret;16 }MS 2012 math.h 1 template inline 2 _Ty _Pow_int(_Ty _X, int _Y) 3 {unsigned int _N; 4 if (_Y >= 0) 5 ... 阅读全文
posted @ 2014-03-11 14:39 卖程序的小歪 阅读(157) 评论(0) 推荐(0)
摘要:class Solution {public: void nextPermutation(vector &num) { if (num.size() =0 && (num[i] >= num[i+1])) i--; if (i >= 0) { ... 阅读全文
posted @ 2014-03-10 22:18 卖程序的小歪 阅读(168) 评论(0) 推荐(0)
摘要:以前好几次在学语言的使用都有实现这个ack函数的经历,今天读本算法书,偶尔又提到了这个,查了下wiki来头好大Values ofA(m,n)m\n01234n012345123456235791135132961125413=65533=265536−3=== 阅读全文
posted @ 2014-03-06 15:13 卖程序的小歪 阅读(768) 评论(0) 推荐(0)