Any of the two numbers in the array, if the preceding number is greater than the number that follows, is called an inverseFor example: 1,2,1,2,1 has 3 reverseIdea: Knowing O (N2) must be wrong. Start to think hash, try to find O (n) algorithm, think for a long time, can not find. Later thought of the sort, with the original array and the array of arrays compared, I write the quick row, or not. Thought for a few hours, helpless to see the answer, the original is a transformation of the merger sor
) { inttemp=*Pstart; *pstart=*Pend; *pend=temp; } }}BOOLIsEven (intN) { return(n1)==0;}voidPreorderoddeven (int* pdata,unsignedintlength) {Preorder (pdata,length,iseven);}voidMain () {inta[5]={1,2,3,4,5}; int* Pdata=A; Preorderoddeven (pdata,5); for(intI=0;i5; i++) cout" "; coutEndl;}Java code: The way to embody extensibility is to write an interface, which puts an abstract method boolean func (int n), and other specific topics, as long as the implementation of this method can
46. Every year, children's Day will prepare some small gifts to visit the children of the orphanage, and this year is also the case. HF as a senior veteran of the cattle, naturally also prepared some small games. Among them, there is a game like this: first, let the children surround a big circle. Then, he randomly assigned a number m, so that the number of children numbered 0 began to count. Every time the child shout to M-1 to sing a song, and then can be in the Gift box arbitrary selection of
Description of the lookup topic in a two-dimensional arrayIn a two-dimensional array, each row is ordered in ascending order from left to right, and each column is sorted in ascending order from top to bottom. Complete a function, enter a two-dimensional array and an integer to determine if the array contains the integer.Enter a description
Array: two-dimensional array to find
Target: The number found
Output description
Find to return True, find not to retur
if(Array = =NULL|| Array.Length ) return; intStart = 0; intEnd = Array.length-1; while(Start end) { //find even numbers from left to right while((Array[start] 1)! = 0) {Start++; } //find odd numbers from right to left while((Array[end] 1)! = 1) {End--; } if(Start end) { inttemp =Array[start]; Array[start]=Array[end]; Array[end]=temp; } } } }2, odd and od
C ++ finds the subscript of the first character that appears only once in the string (NIU kejian refers to offer)
# Include
# Include
Using namespace std; int FirstNotRepeatingChar (string str) {int n = str. length (); if (n
= 0; k --) {if (str [I] = str [k]) break;} if (j
assign to the array on the line.
Solution two run time: 27ms occupied memory: 503k
Public classSolution { Public voidReorderarray (int[]Array) {if(Array. length==0||Array==null) {return; } for(intI=0;iArray. length-1; i++) { for(intj=0;jArray. length-i-1; j + +) {if(Array[j]%2==0Array[j+1]%2==1){inttemp =Array[j];Array[j] =Array[j+1];Array[j+1] = temp; } } } }}Similar to bubble sort, think of using the array[j+1] array do not cross the border. [Sword to
Sword refers to offer generation source code-string Arrangement
Question 1369: String sorting time limit: 1 second memory limit: 32 MB special question: No submitted: 2432 solution: 609 question Description: enter a string, print all characters in the string in Lexicographic Order. For example, if abc is input, all the strings abc, acb, bac, bca, cab, and CBA that can be arranged by characters a, B, and c are printed. Input: each test case contains on
title: Given an array of a[0,1,2...n-1], build an array b[0,1,2,... N-1], so that the element in B is b[i]=a[0]*a[1]*...*a[i-1]*a[i+1]*...*a[n-1], you cannot use division. Solution Ideas:Through the positive and negative two times to seek b[i];Zheng: b[i]=a[0]* ... A[I-1];Inverse: temp = b[n]* ... B[I+1];Finally, the results can be obtained by b[i]*temp.Take a[0,1,2,3,4], b[0,1,2,3,4] For example:Step Analysis:First step: b[0] = 1;Step two: b[1] = b[0] * A[0] = a[0]Step three: b[2] = b[1] * A[1]
Title Description: Enter an array (m*n dimension) that requires the elements of an array to be printed clockwise from the outside.#include void printmatrixcircle (int **numbers,int rows,int columns) { //Verify that the input meets the requirements if (numbers==null| | rowsvoid printmatrixincircle (int **numbers,int rows,int columns,int start) {//left like right print matrix for (int i=start;ivoid Test (int rows,int columns) { printf ("Test begin:%d columns,%d rows.\n", columns,rows);
Problem Description :Enter a list of two increments, merge the two linked lists, and make the nodes in the new list continue to be sorted in ascending order.The implementation code is as follows:#include References:Sword means offerNotes:Reprint Please specify source: http://blog.csdn.net/wsyw126/article/details/51372134WSYW126Sword refers to the surface of offer question 17 merge two sorted list
the first element of the array to compare with the first element and the last element, if the intermediate element is larger than the first element, then the intermediate element must be in the first sequence, then the first pointer to the middle element is arr[2]; If the middle element is small and the last element, Then the middle element must be in the second sequence, and the second pointer points to the middle element.Fourth step: Repeat step two until the first pointer points to the last
There is some trouble with the inference of classification in the book, which is to classify an array of elements by one for 0. If the 3rd digit is 1. So the element x 8 equals or is not equal to 0, so it is not necessary to infer with the first few.def once (array): Reor = 0for x in array:reor ^= xbit1 = firstBit1 (reor) first = 0second = 0for x in array:if x bit1! = 0:first ^= Xelse:second ^= xreturn First, Seconddef firstBit1 (x): n = 1while true:if x n! = 0:return nelse:n "Sword means
The title description enters an array of integers, implements a function to adjust the order of the numbers in the array, so that all the odd digits are placed in the first half of the array, all the even digits are located in the second half of the array, and the relative positions between the odd and odd, even and even are guaranteed. Analysis: The problem is added when practicing on OJ, that is, the order of the adjusted numbers is constant. At present, only one method can be thought of, foll
(array = = null) {throw new RuntimeException ();} int tmp = 0;//Here random initialization does not affect, because count is 0int count = 0;for (Integer a:array) {///if same, add if (tmp = = a) {count++;} else {//if the original If there is a value first, subtract one if (Count > 0) {count--;} else {//original count is 0, change tmptmp = A;count = 1;}}} return TMP;} Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. The sword refers to th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.