Short Java Nice


  • 0
    public class Solution {
        public String largestNumber(int[] nums) {
            if(nums.length == 0) return "0";
            
            PriorityQueue<String> queue = new PriorityQueue<String>(10, new Comparator<String>(){
                public int compare(String a, String b){
                    return  (b + a).compareTo(a + b);
                }});
            for(int i : nums){
                queue.add(String.valueOf(i));
            }
            
            StringBuilder sb = new StringBuilder();
            if(queue.peek().equals("0")){
                return "0";
            }
            while(!queue.isEmpty()){
                sb.append(queue.poll());
            }
            return sb.toString();
        }
    }
    

Log in to reply
 

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