Beautiful 2-lines Java solution


  • 0
    I
    public String largestNumber(int[] nums) {
      String result = IntStream.of(nums).mapToObj(Integer::toString).sorted((num1, num2) -> (num2 + num1).compareTo(num1 + num2)).collect(Collectors.joining(""));
      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.