Defining a two-dimensional array
intnewint*[row_num]; for (int i=0; i<row_num;i++) { newint[col_num]; }
Vector<vector<int>> v2 (row_num,vector<int> (col_num,0)) ;
Delete the duplicate data in the ordinal group and return the length of the remaining array
int a[]: input array
Len:the Array length
Dup:the times that duplicates can be allowed
Return the length of the result array
intRemoveduplicate (intA[],intLenintDUP) { if(Len <=DUP)returnLen; intindex =DUP; for(inti=dup;i<len;i++) { if(A[index-dup]! =A[i]) {A[index++] =A[i]; } } returnindex;}intMain () {intA[] = {1,1,1,2,2,3,4,4,4}; Std::cout<< Removeduplicate (A,9,1) <<" "; Std::cout<< Removeduplicate (A,9,2) <<" "; Std::cout<< Removeduplicate (A,9,3) <<" "; return 0;}
/*******************************************Binary_search to find a target from a rotated Arraylen:the Length of a[]********************************************/intBinary_search (intA[],intLeninttarget) { if(Len <=0) return-1; intFirst =0; intLast =Len; intmid; while(First! =Last ) {Mid= (first + last)/2; if(A[mid] = =target)returnmid; if(A[first] <=A[mid]) { if(A[first] <= target && Target <A[mid]) last=mid; Else First= Mid +1; } Else { if(A[mid] < target && target <= a[last-1]) first= Mid +1; Else Last=mid; } } return-1;}intMain () {intA[] = {7,8,9,1,2,3,4,5,6}; for(intI=1;i<Ten; i++) {Std::cout<< Binary_search (A,9, i) <<" "; } return 0;}
Leetcode1: Linear table