Java 8 solution


  • 1
    public class Solution {
        public String largestNumber(int[] nums) {
            List<String> strings = IntStream.of(nums)
                                            .mapToObj(String::valueOf)
                                            .sorted((a, b) -> (b + a).compareTo(a + b))
                                            .collect(Collectors.toList());
    
            String result = String.join("", strings);
            return result.charAt(0) == '0' ? "0" : result;
        }
    }
    

Log in to reply
 

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