Title DescriptionEnter an array of integers to implement a function that adjusts 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.Look at the code: Public classSolution { Public Static void Reorderarray(int[] arr) {intI,j,target; for(i =1; iif(target%2!=0) {//Odd intTemp for(j =
); }(6) The number to find is larger than the largest number in the array[TestMethod] Public voidFindTest6 () {//1 2 8 9//2 4 9//4 7//6 8//the number to look for is larger than the largest number in the array int[,] matrix = {{1,2,8,9}, {2,4,9, A}, {4,7,Ten, -}, {6,8, One, the } }; Assert.AreEqual (Program.find (Matrix,4,4, -),false); }(7) Robustness test, input null pointer [TestMethod] publicvoid FindTest7 () { // robustness test, input null pointer Assert.AreEqu
that the interviewer really wants. This problem, in fact, we can put the start point in the upper right corner of the array. For example, to find a number larger than the upper-right corner of the number, then find the next line, no, the previous column to find. This way, you can delete a row at a time, reducing the number of traversal times. For example, the process of finding 7:At this point, the equivalent of a total of 5 times we find the number we want to look for, the time complexity is:
Merge two sorted lists
Number of participants: 1527 time limit: 1 seconds space limit: 32768K
By scale: 27.96%
Best record: 0 ms|8552k(from No. 708854 kn)
The title describes the input of two monotonically increasing lists, the output of the list of two linked lists, of course, we need to synthesize the linked list to meet monotonic rules.Topic Link:http://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337?rp=1ru=/ta/coding-interviews Qru=/ta/coding-interviews/quest
pair. Each time we compare, we copy the larger numbers from the back to the secondary array, making sure the numbers in the auxiliary array are ascending. After copying the larger number to the array, move the corresponding pointer forward one bit, then proceed to the next round of comparisons.After the detailed discussion above, we suspect summed up the process of statistical reverse order: First, the array is separated into sub-arrays, the number of reverse pairs in the sub-array is counted,
Java code to implement:/** * Enter an array of integers with positive and negative numbers in the array. One or more consecutive integers in an array make up a sub-array. * The maximum value of all sub-arrays is evaluated. Requires time complexity O (n) */package swordforoffer;/** * @author Jinshuangqi * * August 8, 2015 */public class E31greatestsumofsubarrays {Pub Lic Integer findgreatestsum (int[] arr) {if (arr.length ==0) return null; int greatest = 0x80000000;int Cursum = 0;for (int i = 0
pointer is introduced, so we have to deal with the empty list separately. When the first linked list is an empty list, that is, its head node is a null pointer, then it is merged with the second linked list, and the process of the idler merge is the second linked list. Similarly, when the head node of the second linked list is a null pointer, we combine it with the first linked list to get the first linked list. If two linked lists are empty lists, the result of merging is to get an empty list.
the first number and the last number [TestMethod] publicvoid GetMinNumTest3 () { int 3 4 5 1 2 2 }; 1 ); }(4) There are duplicate numbers, and the number of repetitions is exactly the first and last number. // There are duplicate numbers, and the number of repetitions is exactly the first number and the last number . [TestMethod] publicvoid GetMinNumTest4 () { int 1 0 1 1 1 }; 0 ); }(5) A monotone ascending array, which rotates 0 el
is 1001, 2 bits is 1. So if you enter 9, the function outputs 2. */package swordforoffer;/** * @author Jinshuangqi * * July 30, 2015 */public class E10numberof1inbinary {public int numbe ROF1 (int num) {int count = 0;while (num! = 0) {count++;num = num (num-1);} return count;} public static void Main (string[] args) {e10numberof1inbinary test = new E10numberof1inbinary (); System.out.println (TEST.NUMBEROF1 (9));}} Copyright NOTICE: This article for Bo Master original article, without
array, set the number of times to 1;To iterate over an array:If the next digit is the same as the previous saved number, the number is incremented by 1;If the next number is different from the previously saved number, the number is decremented by 1;If the number is zero, we need to save the next number and set the number to 1.Since the number we are looking for appears to be more than the sum of the number of other numbers appearing, the number to be searched is definitely the last number to be
=i; Break;} - } - returnre; the } - - //determines whether the nth bit on the right is 1 - BOOLIfone (unsignedintAintN) + { - if(a (1N)) + return 1; A Else at return 0; - } - - //The main function. - voidFind_number (vectorint> VEC,int*NUM1,int*num2) - { in if(Vec.empty ()) - return; to intlen=vec.size (); + if(len1) - return; the *Unsignedinta=vec[0]; $ for(intI=1; i)Panax Notoginsenga^=Vec[i]; - the intn=Number_of_first_
numbers are pressed into the stack and the next number is not found, then the sequence cannot be a pop-up sequence.After the formation of clear ideas, we can have some code, the following is the implementation of Java code./** * Enter a sequence of two integers, the first sequence represents the stack's indentation order, and determine if the second sequence is the pop-up order for the stack. */package swordforoffer;import java.util.stack;/** * @author Jinshuangqi * * August 3, 2015 */public cl
, two points, let the middle node to determine the next narrowing of the range (Eg:3 4 5 1 2, the next is 5 1 2, the next is 5 1; when Right-left==1 quits , the time complexity is O (log n), but some examples are not satisfied, eg 1 0 1 1 1 and 1 1 1 0 1) Yes, well, there's a case for this. When both values are equal to the median value, we should move the value of right forward, similar to violence, each error is an enumeration (Eg:1 1 1 1 1) Then you can only enumerate.Do interview questions,
"Disclaimer: All rights reserved, please indicate the source of the reprint, do not use for commercial purposes. Contact mailbox: [Email protected] "Topic Link:http://www.nowcoder.com/practice/94a4d381a68b47b7a8bed86f2975db46?rp=3ru=/ta/coding-interviews Qru=/ta/coding-interviews/question-rankingTitle DescriptionGiven an array a[0,1,..., n-1], build an array b[0,1,..., n-1], where the elements in B b[i]=a[0]*a[1]*...*a[i-1]*a[i+1]*...*a[n-1]. You cannot use division.IdeasWe open an array to stor
Title DescriptionEnter an array of positive integers, combine all the numbers in the array into a number, and print the smallest of all the numbers that can be stitched together. For example, enter the array {3,32,321}, then print out the minimum number that these three numbers can be ranked as 321323.Convert a number to a string and then quickly sort the stringclassSolution { Public:stringPrintminnumber ( vectorint>Numbers) {stringR vectorstring>Sr for(intI=0; I for(intI=0; IreturnR }stringNumb
This article is mainly to share with you the implementation of PHP offer jump step instance hope to help everyone, we first look at an example. A frog can jump up to 1 steps at a time, or jump up to level 2 ... It can also jump on n levels. Ask the frog to jump on an n-level step with a total number of hops.
Idea: According to the Fibonacci sequence:
F (N) =f (N-1) +f (N-2) +f (N-3) +f (N-4) + .... F (2) +f (1)
F (N-1) =f (N-2) +f (N-3) +f (N-4) +
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.