2013年9月4日

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)

2013年9月3日

remove duplicates from sorted array

摘要: 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int step = 0; 7 if( n 0 && A[i] != A[i-1])14 A[i-step] = A[i];15 16 }1... 阅读全文

posted @ 2013-09-03 22:46 jumping_grass 阅读(151) 评论(0) 推荐(0)

remove elements

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

posted @ 2013-09-03 22:37 jumping_grass 阅读(155) 评论(0) 推荐(0)

permutation sequence

摘要: 1 class Solution { 2 public: 3 string getPermutation(int n, int k) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( k flag(n, 0 ); 9 for( int i=0;i=1;i--)13 N *= i;14 if( k > N ) k = k % N;15 16 ... 阅读全文

posted @ 2013-09-03 21:45 jumping_grass 阅读(211) 评论(0) 推荐(0)

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 || k == 0 ) return head; 7 ListNode * root = new ListNode (0); 8 root -> nex... 阅读全文

posted @ 2013-09-03 21:18 jumping_grass 阅读(139) 评论(0) 推荐(0)

unique path2

摘要: 1 class Solution { 2 public: 3 int helper(vector > &G, vector > &S,int r, int c ) 4 { 5 if( r == G.size()-1 && c == G[0].size()-1 && G[r][c]!=1 ) return 1; 6 if( r = G.size() || c = G[0].size() || G[r][c] == 1) 7 return 0; 8 if( S[r][c] != -1 ) return S... 阅读全文

posted @ 2013-09-03 20:54 jumping_grass 阅读(185) 评论(0) 推荐(0)

search a 2d box

摘要: 1 class Solution { 2 public: 3 bool searchMatrix(vector > &matrix, int target) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if(matrix.empty() || matrix[0].empty() ) return false; 7 int left = 0; 8 int right = matri... 阅读全文

posted @ 2013-09-03 19:43 jumping_grass 阅读(129) 评论(0) 推荐(0)

sort colors

摘要: 1 class Solution { 2 public: 3 void sortColors(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int left = 0; 7 int right = n-1; 8 9 int i=0;10 int j = n-1;11 12 while( ... 阅读全文

posted @ 2013-09-03 19:33 jumping_grass 阅读(139) 评论(0) 推荐(0)

word search

摘要: 1 class Solution { 2 public: 3 bool travel(vector > &board,int r,int c, 4 vector > &flag, string word,int pos) 5 { 6 if( pos == word.length() ) return true; 7 if( r=board.size() || c=board[0].size()) 8 return false; 9 if(!flag[r][c] || word[po... 阅读全文

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

partion list

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

posted @ 2013-09-03 16:39 jumping_grass 阅读(142) 评论(0) 推荐(0)

导航