English: Given A list of non negative integers, arrange them such that they form the largest number.
English: Give a set of nonnegative integers to find the maximum number of non-negative integers that can be spliced out
Description: For example, give an array of [3, 30, 34, 5, 9], the maximum number of stitching out is 9534330
The correct sorting method is to compare two strings (set to A and b) in sequential order using the Sort method, and two strings a+b and B+a, if the a+b is larger, then A is in front b after, otherwise A is in front B.
Public classSolution { Public StaticString Largestnumber (int[] nums) {string[] array=NewString[nums.length]; for(inti = 0; i < nums.length; i++) {Array[i]=string.valueof (Nums[i]); } String temp; for(inti = 0; i < Array.Length; i++) { for(intj = i+1; J < Array.Length; J + +) { if((Array[i] + array[j]). CompareTo (Array[j] + array[i]) < 0) {Temp=Array[i]; Array[i]=Array[j]; ARRAY[J]=temp; } } } if(Array[0].equals ("0")) return"0"; Else { returnString.Join ("", array); } } Public Static voidMain (string[] args) {int[] Nums = {3, 30, 34, 5, 9}; String Largestnum=Largestnumber (nums); System.out.println (Largestnum); }}
[Daily programming] largest number-give a set of nonnegative integers to find the maximum numbers that can be spliced out of these nonnegative integers