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)

container with te most water

摘要: 1 class Solution { 2 public: 3 int maxArea(vector &height) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( height.size() height[right] )15 right --;16 else17 {18 left ++ ;1... 阅读全文

posted @ 2013-09-04 09:54 jumping_grass 阅读(145) 评论(0) 推荐(0)

导航