Simple java solution


  • 2
    L
    public String largestNumber(int[] nums) {
        String[] strs = new String[nums.length];
        for(int i = 0; i < nums.length; i++){
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs,(str1,str2) -> (str2 + str1).compareTo(str1 + str2));
        if(strs[0].equals("0")) return "0";
        StringBuilder sb = new StringBuilder();
        for(String str : strs) sb.append(str);
        return sb.toString();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.