2013年9月3日

grey code

摘要: 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 7 8 vector vec(pow(2.0,n),0); 9 for(int i=1;i=pow(2.0,i-1); j-- )12 {13 vec[j... 阅读全文

posted @ 2013-09-03 15:38 jumping_grass 阅读(122) 评论(0) 推荐(0)

decode ways

摘要: 1 class Solution { 2 public: 3 4 bool check(string s) 5 { 6 if( s.length() == 1 ) 7 return s>="1" && s = "10" && s = s.length() ) return 1;16 17 if( left == right) 18 {19 if(s[left]>='1'&&s[left] right ) return 1;25 26 ... 阅读全文

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

subsets 2

摘要: 1 class Solution { 2 public: 3 vector > vec; 4 void subsets(vector &S,vector &v, int start) 5 { 6 vec.push_back(v); 7 for(int i=start;i > subsetsWithDup(vector &S) {17 // Start typing your C/C++ solution below18 // DO NOT write int main() function19 ... 阅读全文

posted @ 2013-09-03 14:57 jumping_grass 阅读(149) 评论(0) 推荐(0)

reverse linked list2

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

posted @ 2013-09-03 14:40 jumping_grass 阅读(161) 评论(0) 推荐(0)

restore IP addresses

摘要: 1 class Solution { 2 private: 3 vector ret; 4 int pos[4]; 5 public: 6 bool check(string &s, int beg, int end) 7 { 8 string ip(s, beg, end - beg + 1); 9 if (ip.size() == 1)10 return "0" restoreIpAddresses(string s) {47 // Start typing your C/C++ s... 阅读全文

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

unique binary search tree

摘要: 1 class Solution { 2 public: 3 vector generate(int left,int right ) 4 { 5 vector vec; 6 7 if( left > right ) 8 vec.push_back( NULL ); 9 10 for(int i=left;i vec1 = generate(left,i-1);13 vector vec2 = generate(i+1,right);14 ... 阅读全文

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

2013年9月1日

word ladder

摘要: 1 class Solution { 2 public: 3 int ladderLength(string start, string end, unordered_set &dict) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( dict.empty() ) return 0; 7 if( start == end ) return 0; 8 int len = ... 阅读全文

posted @ 2013-09-01 16:09 jumping_grass 阅读(169) 评论(0) 推荐(0)

2013年7月26日

答题卡规格

摘要: 答案卡高度规则,如果答案卡行数为N,则高度为120*N+361-20题:156 21-40题:276 41-60题:396 61-80题:516 81-100题:636 101-120题:756 121-140题:876 141-160题:996 宽度为1000 阅读全文

posted @ 2013-07-26 22:38 jumping_grass 阅读(467) 评论(0) 推荐(0)

2013年7月5日

valid binary search tree

摘要: class Solution {public: bool valid(TreeNode *node, stack& s) { if( node == NULL ) return true; stack left,right; if( !valid(node->left,left) ) return false; if( !left.empty() ) { if( left.top() >= node->val ) {... 阅读全文

posted @ 2013-07-05 21:55 jumping_grass 阅读(159) 评论(0) 推荐(0)

remove nth node from end of list

摘要: class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if( head == NULL ) return head; ListNode * root = new ListNode(-1); root->next = head; while(... 阅读全文

posted @ 2013-07-05 19:56 jumping_grass 阅读(115) 评论(0) 推荐(0)

导航