2013年7月4日

Jump Game

摘要: class Solution {public:int jump(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if( n==0 || n == 1 ) return 0; int cur = 0,newCur = 0; int step = 0; while( cur = n-1 ) return step+1; int flag ... 阅读全文

posted @ 2013-07-04 21:36 jumping_grass 阅读(186) 评论(0) 推荐(0)

merge intervals

摘要: 1 bool cmp(Interval a,Interval b) 2 { 3 return a.start merge(vector &intervals) { 8 // Start typing your C/C++ solution below 9 // DO NOT write int main() function10 vector v;11 if( intervals.size() == 1 || intervals.empty() ) return intervals;12 13 ... 阅读全文

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

merge interval

摘要: 1 class Solution { 2 public: 3 vector insert(vector &intervals, Interval newInterval) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector v; 7 if( intervals.empty () ) { v.push_back(newInterval); return v;} 8 9 ... 阅读全文

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

spiral matrix

摘要: 1 class Solution { 2 public: 3 4 vector> generateMatrix(int num) { 5 // Start typing your C/C++ solution below 6 // DO NOT write int main() function 7 8 vector> v(num,vector(num,0)); 9 10 int m ,n;11 m = n = num;12 if( m == 0 )... 阅读全文

posted @ 2013-07-04 17:23 jumping_grass 阅读(135) 评论(0) 推荐(0)

unique paths

摘要: class Solution {public: int rows; int cols; int path(int m,int n, vector> &v) { if( m==rows-1 && n == cols-1 ) return 1; if( v[m][n] != INT_MAX ) return v[m][n]; int way1 = 0,way2 = 0; if( m > v( m, vector(n,INT_MAX)); return path(0,0,v); }};... 阅读全文

posted @ 2013-07-04 14:43 jumping_grass 阅读(116) 评论(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 ) 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)

导航