Sword refers to the 20th question on offer, nine degrees OJ on the test pass.
Topic Description:
Enter a matrix and print each number in clockwise order from the outside, for example, if you enter the following matrix:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Then print the 1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 of the words in sequence.
Input:
The input may contain multiple test samples, for each test case,
The first line entered consists of
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. Thinking of solving problemsTime To change space:Thought can refer to insert sort. Time complexity O (n^2), Space complexity O (1)Class Solution {public: void
Title: Move a number of elements at the beginning of an array to the end of the array, which we call the rotation of the array. Enter a rotation of an incrementing sorted array, outputting the smallest element of the rotated array. For example, enter {1,2,3,4,5} for a rotation of {3,4,5,1,2}, the minimum value of this array is 1.The rotated array contains two ascending-sorted sub-arrays, and the second subarray has a shadowed background.As shown in the following:(1) Point Pl to the first number
from the first number??In addition, it is possible that the preceding strings are obediently is the number, the middle of an unusual character, then we need to do this time to divide the situation, the first we can keep the previous number, discard the exception character behind the thing, the second is we directly simple rude return error??There is a string representation of the number may be large, it is possible to cross the border, then we should do, can output, out of bounds, can also retu
this question, if we put all the number of different or up, then we get the two number of different or up value, set the two number is X, Y.
A1^a2^a3^...^an=x^y = z! = 1.
Then we envision whether we can divide it into two categories. We find the lowest bit of Z 1 and then analyze it, and we can draw
1. There must be an odd number of this number in the n number of 1,
sorted out the number of 5 , Arrays.sort (array), and then iterate through the array of 0 of the number of arrays, in addition, if you find two zeros, there is no need to continue, you can jump out of the loop??for (int i=0;iif (array[i]==0) numof0++;if (numof0==2) break;}??Alternatively, you can put the if judgment statement in the For loop, so that you can enter the number of times the loop body, reduce the number of traversal?? for (int i=0;i??Then start with the first index1 not 0 , int in
int hi = numbers.length-1; Set the initial value int mi = lo; Make sure that the LO is in the previous ordered part, HI is in the latter part of the order while (Numbers[lo] >= Numbers[hi]) {//When the processing range has only two data, the latter result is returned Because Numbers[lo] >= Numbers[hi] is always true, the latter result corresponds to the smallest value if (Hi-lo = = 1) {return Numbers[hi]; }//Take the middle position mi = lo + (Hi-lo)/2;
Longfabn; if(n2) Fabn=Arrary[n]; Long LongFabone=1; Long Longfabtwo=0; for(unsignedintI=2; ii) {fabn=fabone+Fabtwo; Fabtwo=Fabone; Fabone=fabn; } returnfabn;}voidMain () {Long LongN=fabonacci ( the); coutEndl;}Title Two: A frog can jump up a step at a time, you can jump up to 2 steps, the frog jumped on the number of steps on the N-step method.Idea: When there is only one step, the frog's jumping method is only one. When there are two steps, there are two kinds of frog jumping method (one i
Original blog, reproduced please indicate the source! # topics # ideas Set two auxiliary variables small and big,small represent the minimum value of the sequence, and big represents the maximum value of the sequence. If sum (small ~ big) > S, the value of small is increased. If sum (small ~ big) # code #include #includeusing namespacestd;classSolution { Public: Vectorint> > Findcontinuoussequence (intsum) { //Resultsvectorint> >Res; //Special Input if(sum3) returnRes
function, to enter such a two-dimensional array and an integer to determine if the array contains the integer. + */ - /* the idea: The key is to find the law, starting from the upper right corner to judge, gradually remove the row or column (change to the line number or column number of simple operation) * */ $ Public BooleanFind (intTargetint[] Array) {Panax Notoginseng inti = 0,len = Array.Length;//Number of rows - intj = Array[0].length-1; the whi
the biggest pit. In the JS language do not blindly return null or something, mainly to see the topic, if the return of more than an empty array [], a single return 0 or something. This pit for a day .... =-= function permutation (str) {Let ans = []; Let arr = Str.split (""); if (str.length===0) return []; DFS (ans,arr,0); Ans.map (function (item,index) {//Return Item.join (""); }) ans = ans.filter (function (item,index) {return Ans.indexof (item) ===index; }); return Ans.sort
Title: Merging two sorted listsTitle Description: Input two monotonically increasing list, output two linked list of the linked list, of course, we need to synthesize the linked list to meet the monotone non-reduction rules.The idea that the problem is not difficult to feel, that is, under the discussion of the situation, there are two ways of circulation recursion1 Public classSolution {2 PublicListNode Merge (listnode list1,listnode list2) {3 if(list1==NULLlist2==NULL)return NULL;4
Topic 1370: Digital time limit for more than half occurrences in an array: 1 seconds Memory limit: 32 Mega Special: No submission: 2844 Resolution: 846 title Description: There is a number in the array that appears more than half the length of the array, please find this number. For example, enter an array of length 9 {1,2,3,2,2,2,5,4,2}. Since the number 2 appears in the array 5 times, which exceeds half the length of the array, the output is 2. Input: Each test case consists of 2 rows: The fir
Topic 1372: Maximum sub-vectors and (maximum and duration of contiguous subarray) time limit: 1 seconds Memory limit: 32 Mega Special: No submission: 2169 Resolution: 570 Topic Description: Hz occasionally take some professional questions to confuse those non-computer majors. Today JOBDU Test team after the meeting, he said again: in the Ancient one-dimensional pattern recognition, it is often necessary to calculate the maximum sum of continuous sub-vectors, when the vector is all positive, the
Title: Enter an array of integers to implement a function to adjust the order of the numbers in the array, so that all the odd digits are in the first half of the array, all the even digits are in the second half of the array, and the relative positions of the odd and odd, even and even are constant. Public voidReorderarray (int[] Array) { for(inti = 0; i ) { intIndexeven = 0; BooleanFlageven =false; for(intj = 0; J ) { if((Array[j] 1) = = 1) { if(flageven)
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.