There are two ordered arrays, a, B, and the lengths are m,n; use an algorithm with a time complexity of m+n to merge the two arrays into an ordered array of C.
1 Static voidMain (string[] args)2 {3 int[] A = {1,3,5,6,6,7, - };4 int[] B = {2,3,4,6,7, -, -, - };5 6 varClength = A.length +b.length;7 int[] C =New int[clength];8 inti =0, j =0, k =0;9 Ten for(i =0, j =0, k =0; (I < A.length | | J < b.length) && K < (a.length + b.length); i++, J + +, k++) One { A if(i>=a.length) - { -C[K] =B[j]; the Continue; - } - - if(J >=b.length) + { -C[K] =A[i]; + Continue; A } at - if(A[i] >B[j]) - { -C[K] =B[j]; -i--; - } in Else - { toC[K] =A[i]; +j--; - } the } * $ for(intL =0; L < C.length; l++)Panax Notoginseng { - System.Console.Write (C[l]); the } + A System.Console.Read (); the}
This is, soon to a company encountered a problem, in fact, this understanding of the meaning of the topic, think carefully about the logic, or do it. May just start to do when a little nervous, the most afraid of the pen test company,
Too long did not take a pen to write, look at the crooked handwriting is uncomfortable, write a mess! Fortunately, to the interviewer to express the logic of clear!
Seems to need to calm down, practice the word! The Spring Festival is coming soon, happy Spring! I hope to be able to further my life and career in the 2015.
Fighting for me,my Dear Darling,my family, ~o (∩_∩) o~.
Array--merge two ordered arrays, a, a, into a new ordered array C