2013年9月6日

interleaving string

摘要: 1 class Solution { 2 3 public: 4 bool isInterleave(string s1, string s2, string s3) { 5 // Start typing your C/C++ solution below 6 // DO NOT write int main() function 7 if (s1.size() + s2.size() != s3.size()) 8 return false; 9 10 vector> f(... 阅读全文

posted @ 2013-09-06 12:34 jumping_grass 阅读(155) 评论(0) 推荐(0)

distinct subsequences

摘要: 1 class Solution { 2 public: 3 int helper(vector> &v, string S,int i, string T, int j) 4 { 5 if( T.length() == j ) return 1; 6 if( T.length() - j > S.length() - i ) return 0; 7 int sum = 0; 8 if( v[i][j] != -1 ) return v[i][j]; 9 for(int k = i;k> v(S.... 阅读全文

posted @ 2013-09-06 11:09 jumping_grass 阅读(151) 评论(0) 推荐(0)

2013年9月5日

longest palindromic substring 有问题

摘要: 1 class Solution { 2 public: 3 string LCS( string& str1,string& str2){ 4 int xlen=str1.size(); //横向长度 5 vector tmp(xlen); //保存矩阵的上一行 6 vector arr(tmp); //当前行 7 int ylen=str2.size(); //纵向长度 8 int maxele=0; //矩阵元素中的最大值 9 int pos=0... 阅读全文

posted @ 2013-09-05 16:24 jumping_grass 阅读(132) 评论(0) 推荐(0)

2013年9月4日

anagrams

摘要: 1 class Solution { 2 public: 3 vector anagrams(vector &strs) { 4 vector res; 5 if (strs.size() anagram; 7 for (int i = 0; i = 0) {15 res.push_back(strs[anagram[s]]);16 anagram[s] = -1;17 }18 res.pus... 阅读全文

posted @ 2013-09-04 23:00 jumping_grass 阅读(130) 评论(0) 推荐(0)

maximun subarray

摘要: 1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector vec( n, 0 ); 7 int m = vec[0] = A[0]; 8 for(int i=1;i<n;i++) 9 {10 vec[i] = vec... 阅读全文

posted @ 2013-09-04 19:31 jumping_grass 阅读(98) 评论(0) 推荐(0)

next permutation

摘要: 1 class Solution { 2 public: 3 void nextPermutation(vector &num) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( num.size() == 1 ) return; 7 int pos = -1; 8 for(int i = num.size() - 1; i>=1; i-- ) 9 if... 阅读全文

posted @ 2013-09-04 19:16 jumping_grass 阅读(143) 评论(0) 推荐(0)

permutation2

摘要: 1 class Solution { 2 public: 3 vector > permuteUnique(vector &num) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector > vec; 7 if( num.empty() ) return vec; 8 9 sort( num.begin(),num.end() );10 ve... 阅读全文

posted @ 2013-09-04 16:08 jumping_grass 阅读(156) 评论(0) 推荐(0)

strStr

摘要: 1 class Solution { 2 public: 3 void get_nextval(const char *T, int next[]) 4 { 5 // 求模式串T的next函数值并存入数组 next。 6 int j = 0, k = -1; 7 next[0] = -1; 8 while ( T[j] != '\0' ) 9 {10 if (k == -1 || T[j] == T[k])11 {12 ... 阅读全文

posted @ 2013-09-04 14:46 jumping_grass 阅读(182) 评论(0) 推荐(0)

merge k sorted lists

摘要: 1 bool cmp(ListNode * a ,ListNode * b ) 2 { 3 return a->val >= b-> val; 4 } 5 class Solution { 6 public: 7 ListNode *mergeKLists(vector &lists) { 8 // Start typing your C/C++ solution below 9 // DO NOT write int main() function10 if( lists.empty() ) return NULL;11 ... 阅读全文

posted @ 2013-09-04 10:24 jumping_grass 阅读(205) 评论(0) 推荐(0)

two sum

摘要: 1 bool cmp(pair a, pair b ) 2 { 3 return a.first twoSum(vector &numbers, int target) { 8 // Start typing your C/C++ solution below 9 // DO NOT write int main() function10 vector res;11 if( numbers.size() > v(numbers.size(), pair(0,0));14 for(int i=0;i<n... 阅读全文

posted @ 2013-09-04 10:03 jumping_grass 阅读(221) 评论(0) 推荐(0)

导航