2013年9月6日

median of two sorted arrays

摘要: 1 double findKth(int a[], int m, int b[], int n, int k) 2 { 3 //always assume that m is equal or smaller than n 4 if (m > n) 5 return findKth(b, n, a, m, k); 6 if (m == 0) 7 return b[k - 1]; 8 if (k == 1) 9 return min(a[0], b[0]);10 //divide k into two pa... 阅读全文

posted @ 2013-09-06 19:54 jumping_grass 阅读(158) 评论(0) 推荐(0)

first missing positive

摘要: 1 class Solution { 2 public: 3 int firstMissingPositive(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if (n == 0) return 1; 7 int i=0; 8 while(i0 && A[i] < n && A[A[i]-1]!=A[i])11 {12 ... 阅读全文

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

substring with concatenation

摘要: 1 class Solution { 2 public: 3 vector findSubstring(string S, vector &L) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector v; 7 if( L.empty() ) return v; 8 int wn = L.size(); 9 int wl = L[0].size();10 ... 阅读全文

posted @ 2013-09-06 17:05 jumping_grass 阅读(162) 评论(0) 推荐(0)

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)

导航