C# solution: check 0 first, compare two numbers conjoin as a string because of "30" & "3"


  • 0
    B
    public class Solution
    {
    	public string LargestNumber(int[] nums)
    	{
    		if (nums.All(c => c == 0)) return "0";
    
    		Array.Sort(nums, (a,b) => $"{b}{a}".CompareTo($"{a}{b}"));
    
    		return string.Join("", nums);
    	}
    }
    

Log in to reply
 

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