9line JAVA Solution


  • 1
    Y
    public class Solution {
        public String largestNumber(int[] nums) {
            String[] what = Arrays.stream(nums).mapToObj(i -> ((Integer) i).toString()).toArray(String[]::new);
            Arrays.sort(what, new Comparator<String>(){
                public int compare(String a, String b){
                    String str1 = a + b;
                    String str2 = b + a;
                    return str2.compareTo(str1);
                }
            });
            return what[0].equals("0") ? "0" : String.join("", what);
        }
    }

Log in to reply
 

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