月份:2017年8月

[LeetCode]Largest Number

[LeetCode]Largest Number

简单的字符串排序
比较S2+S1和S1+S2

    public class Solution
    {
        public string LargestNumber(int[] nums)
        {
            List<string> Nums = new List<string>();
            foreach (var temp in nums)
            {
                Nums.Add(Convert.ToString(temp));
            }
            Nums.Sort(Compare);
            string RetData = "";
            foreach (var temp in Nums)
            {
                RetData = string.Concat(RetData, temp);
            }
            int ZeroCount = 0;
            for (ZeroCount = 0; ZeroCount < RetData.Length; ZeroCount++)
            {
                if (RetData[ZeroCount] == '0') continue;
                if (RetData[ZeroCount] != '0') break;
            }
            RetData = RetData.Remove(0, ZeroCount);
            if (RetData == "") RetData = "0";
            return RetData;
        }
        private int Compare(string Comp1, string Comp2)
        {
            return string.Compare(string.Concat(Comp2, Comp1), string.Concat(Comp1, Comp2));
        }
    }