2013年9月8日

scramble string

摘要: 1 class Solution { 2 public: 3 bool isScramble(string s1, string s2) { 4 // Start typing your Java solution below 5 // DO NOT write main() function 6 string m = s1; 7 string n = s2; 8 sort(m.begin(),m.end()); 9 sort(n.begin(),n.end());10 if( m... 阅读全文

posted @ 2013-09-08 13:46 jumping_grass 阅读(158) 评论(0) 推荐(0)

edit distance

摘要: class Solution {public: int minDistance(string word1, string word2) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > f(word1.size()+1, vector(word2.size()+1)); f[0][0] = 0; for(int i = 1; i <= word2.size(); i++) ... 阅读全文

posted @ 2013-09-08 11:19 jumping_grass 阅读(211) 评论(0) 推荐(0)

simplify path

摘要: class Solution {public: string simplifyPath(string path) { // Start typing your C/C++ solution below // DO NOT write int main() function stack s; string str; for(int i = 0; i < path.size(); i++) { if (path[i] == '/') { ... 阅读全文

posted @ 2013-09-08 11:07 jumping_grass 阅读(158) 评论(0) 推荐(0)

pow(x,n)

摘要: 1 class Solution { 2 public: 3 4 double pow(double x, int n) { 5 // Start typing your C/C++ solution below 6 // DO NOT write int main() function 7 if( abs(x-1) == 0 || (abs(x+1) ==0 && n%2 == 0)) return 1.00000; 8 if( abs(x+1) == 0 && n%2 == 1) return -1.00... 阅读全文

posted @ 2013-09-08 10:46 jumping_grass 阅读(137) 评论(0) 推荐(0)

2013年9月7日

mutiply strings

摘要: 1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector r( num1.length()+num2.length(),0); 7 int c = 0; 8 for(int i=num1.length()-1;i>=0;i--) 9 ... 阅读全文

posted @ 2013-09-07 20:23 jumping_grass 阅读(368) 评论(0) 推荐(0)

Roman to Integer

摘要: 1 class Solution { 2 public: 3 int switchRoman( char a ) 4 { 5 if( a == 'M' ) 6 return 1000; 7 else if( a == 'D' ) 8 return 500; 9 else if( a == 'C' )10 return 100;11 else if( a == 'L' )12 return 50;13 ... 阅读全文

posted @ 2013-09-07 18:11 jumping_grass 阅读(149) 评论(0) 推荐(0)

integer to roman

摘要: 1 class Solution { 2 public: 3 string intToRoman(int number) { 4 int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; 5 string numerals[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", & 阅读全文

posted @ 2013-09-07 17:44 jumping_grass 阅读(121) 评论(0) 推荐(0)

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)

导航