用几个数字任意组合成最大数

例如12,34,56,56,672

组合成最大数为67256563412

原题:

Given a list of non negative integers, arrange them such that they form the largest number.

For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.

Note: The result may be very large, so you need to return a string instead of an integer.

class Solution {
    public String largestNumber(int[] nums) {
        String[] input = new String[nums.length];
        for(int i = 0;i() {
            @Override
            public int compare(String o1, String o2) {//覆写元素的比较规则
                for(int i = 0; i < o1.length() + o2.length(); i++) {
                    char p1 = o1.charAt(i % o1.length());
                    char p2 = o2.charAt(i % o2.length());
                    if(p1 != p2) return p2 - p1;
                }
                return 0;
            }
        });
        String result = "";
        for(String s : input) {
            result += s;
        }
        int a = 0;
        for(int i = 0;i



你可能感兴趣的:(用几个数字任意组合成最大数)