Share my csharp solution 117ms

  • 1
    public class Solution{
        public string LargestNumber(int[] num)
            //This is awkward ;( just for test case
            if (Array.TrueForAll(num, x => x == 0))
                return "0";
            return String.Concat(num);
        private static int CompareNum(int a, int b)
            string sa = b.ToString();
            string sb = a.ToString();
            return (sa + sb).CompareTo(sb + sa);


  • 0

    You could probably optimize it by checking num[0] == 0 after sorting, instead of using TrueForAll to check all elements for the "0" case.

Log in to reply

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