2013年7月4日

rotate list

摘要: 1 class Solution { 2 public: 3 ListNode *rotateRight(ListNode *head, int k) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( head == NULL ) return head; 7 ListNode * root= new ListNode(-1); 8 root->next = head; 9 ... 阅读全文

posted @ 2013-07-04 14:33 jumping_grass 阅读(121) 评论(0) 推荐(0)

merge two sorted list

摘要: 1 class Solution { 2 public: 3 ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 ListNode* root = new ListNode(-1); 7 ListNode* ptr = root; 8 while( l1!= NULL && l2 !=... 阅读全文

posted @ 2013-07-04 13:26 jumping_grass 阅读(148) 评论(0) 推荐(0)

add binary

摘要: 1 class Solution { 2 public: 3 string addBinary(string a, string b) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( a == "" ) return b; 7 if( b == "" ) return a; 8 9 if( a.length() > b.length() )... 阅读全文

posted @ 2013-07-04 13:20 jumping_grass 阅读(110) 评论(0) 推荐(0)

test justification

摘要: 1 vector fullJustify(vector &words, int L) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 vector v; 5 string s = ""; 6 for( int i=0; i< words.size(); ) 7 { 8 int l = words[i].length(); 9 ... 阅读全文

posted @ 2013-07-04 10:19 jumping_grass 阅读(173) 评论(0) 推荐(0)

remove duplicates from sorted list

摘要: ListNode *deleteDuplicates(ListNode *head) { // Start typing your C/C++ solution below // DO NOT write int main() function if( head == NULL ||head->next == NULL ) return head; ListNode * root = new ListNode (-1 ); root -> next = head; ListNode *ptr = hea... 阅读全文

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

sqrt(x)

摘要: 1 int sqrt(int x) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 if( x==0 || x==1) return x; 5 int low = 1; 6 int top = x/2; 7 while( low <= top ) 8 { 9 int mid = (top + low)/2;10 ... 阅读全文

posted @ 2013-07-04 00:30 jumping_grass 阅读(161) 评论(0) 推荐(0)

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)

导航