2013年7月3日

sort colors

摘要: 1 void swap( int &a, int &b ) 2 { 3 int tmp = a; 4 a = b; 5 b = tmp; 6 return; 7 } 8 void sortColors(int A[], int n) { 9 // Start typing your C/C++ solution below10 // DO NOT write int main() function11 int r = 0, w = 0, b = n-... 阅读全文

posted @ 2013-07-03 23:27 jumping_grass 阅读(121) 评论(0) 推荐(0)

Valid Soduku

摘要: 1 bool isValidSudoku(vector > &board) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 vector > rows(9, vector(9, false)); 5 vector > cols(9, vector(9, false)); 6 vector > blocks(9, vector(9, false)); 7 8 for (int... 阅读全文

posted @ 2013-07-03 21:22 jumping_grass 阅读(177) 评论(0) 推荐(0)

count and say

摘要: string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function string s = "1"; while( n>1 ) { string t=""; int i = 0; while( i < s.length() ) { int count = 1; ... 阅读全文

posted @ 2013-07-03 19:59 jumping_grass 阅读(128) 评论(0) 推荐(0)

reverse k group

摘要: 1 ListNode *reverseKGroup(ListNode *head, int k) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 if( knext = head; 8 ListNode* ptr1 = root; 9 ListNode* ptr2 ;10 ListNode* tmp, *tmp2,*tmp3;11 12 ... 阅读全文

posted @ 2013-07-03 19:25 jumping_grass 阅读(209) 评论(0) 推荐(0)

search for range

摘要: 1 class Solution { 2 public: 3 vector searchRange(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector v(2,-1); 7 8 int l = 0, m , r = n-1; 9 10 while( l=0 && A[r] == target ) v... 阅读全文

posted @ 2013-07-03 17:49 jumping_grass 阅读(140) 评论(0) 推荐(0)

search insert position

摘要: 1 class Solution { 2 public: 3 int searchInsert(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int lt = 0, rt = n-1; 7 while(lt target )13 rt = mid - 1;14 else 15 ... 阅读全文

posted @ 2013-07-03 17:31 jumping_grass 阅读(151) 评论(0) 推荐(0)

生成括号组合

摘要: void generate( int n_match, int sum, vector& v ) { if( n_match v1 = v; vector v2 = v; v.clear(); for( int i=0; i 0 ) { for( int i=0; i generateParenthesis(int n) { // Start typing your C/C++ solution below ... 阅读全文

posted @ 2013-07-03 17:21 jumping_grass 阅读(180) 评论(0) 推荐(0)

导航