标签:重复 sed ext 重叠 replace http for gif 操作
class Solution { public: bool Find(vector<vector<int> > array,int target) { if(array.size()==0)return false; int r=array.size(); int c=array[0].size(); int i=r-1,j=0; while(i<r&&i>-1&&j<c&&j>-1){ if(array[i][j] == target)return true; if(array[i][j]>target){ i--; }else{ j++; } } return false; } };
//length为牛客系统规定字符串输出的最大长度,固定为一个常数 class Solution { public: void replaceSpace(char *str,int length) { int i = 0; int j = 0; int nSpace = 0; char *pStr = NULL; pStr = (char*)malloc(sizeof(char)*length * 3); for (i = 0, j = 0; i<length; i++, j++) { if (‘ ‘ == str[i]) { pStr[j] = ‘\%‘; pStr[++j] = ‘2‘; pStr[++j] = ‘0‘; } else { pStr[j] = str[i]; } } for( i=0;i<j;i++ ) { str[i] = pStr[i]; } free(pStr); pStr = NULL; } };
/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : * val(x), next(NULL) { * } * }; */ class Solution { public: vector<int> printListFromTailToHead(struct ListNode* head) { struct ListNode* tmp = head; vector<int>v; while(tmp != NULL){ v.push_back(tmp->val); tmp = tmp->next; } reverse(v.begin(),v.end()); return v; } };
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: struct TreeNode* reConstructBinaryTree(vector<int> pre,vector<int> in) { int in_size = in.size(); if (in_size == 0) return NULL; vector<int> pre_left, pre_right, in_left, in_right; int val = pre[0]; TreeNode* node = new TreeNode(val);//root node is the first element in pre int p = 0; for (; p < in_size; ++p){ if (in[p] == val) //Find the root position in in break; } for (int i = 0; i < in_size; ++i){ if (i < p){ in_left.push_back(in[i]);//Construct the left pre and in pre_left.push_back(pre[i + 1]); } else if (i > p){ in_right.push_back(in[i]);//Construct the right pre and in pre_right.push_back(pre[i]); } } node->left = reConstructBinaryTree(pre_left, in_left); node->right = reConstructBinaryTree(pre_right, in_right); return node; } };
class Solution { public: void push(int node) { stack1.push(node); } int pop() { if(stack2.empty()){ while(!stack1.empty()){ stack2.push(stack1.top()); stack1.pop(); } } int node = stack2.top(); stack2.pop(); return node; } private: stack<int> stack1; stack<int> stack2; };
class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { int i=0; int len = rotateArray.size(); if(len==0)return 0; if(len==1)return rotateArray[0]; while(i<len-1){ if(rotateArray[i]<=rotateArray[i+1]){ i++; }else{ break; } } return rotateArray[i+1]; } };
class Solution { public: int Fibonacci(int n) { if(n == 0) return 0; if(n == 1) return 1; int numfn1 = 0, numfn2 = 1; int currentnum; for(int i=2; i<=n; ++i) { currentnum = numfn1+numfn2; numfn1 = numfn2; numfn2 = currentnum; } return currentnum; } };
class Solution { public: int jumpFloor(int number) { if (number == 1)return 1; if (number == 2)return 2; int val; int num1=1; int num2=2; while(number-->2){ val = num1+num2; num1 = num2; num2 = val; } return val; } };
class Solution { public: int jumpFloorII(int number) { int f=1,fn=1; for(int i=2;i<=number;i++){ fn=2*f; f=fn; } return fn; } };
class Solution { public: int rectCover(int number) { if(number==1)return 1; if(number==2)return 2; int n1=1,n2=2,val=0; for(int i=2;i<number;i++){ val = n1 + n2; n1=n2; n2=val; } return val; } };
标签:重复 sed ext 重叠 replace http for gif 操作
原文地址:http://www.cnblogs.com/yuguangyuan/p/6046804.html