代码拉取完成,页面将自动刷新
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Comparer: IComparer<string>
{
public int Compare(string left, string right)
{
return Compare(left, right, 0, 0);
}
private int Compare(string left, string right, int lBegin, int rBegin)
{
var len = Math.Min(left.Length - lBegin, right.Length - rBegin);
for (var i = 0; i < len; ++i)
{
if (left[lBegin + i] != right[rBegin + i])
{
return left[lBegin + i] < right[rBegin + i] ? -1 : 1;
}
}
if (left.Length - lBegin == right.Length - rBegin)
{
return 0;
}
if (left.Length - lBegin > right.Length - rBegin)
{
return Compare(left, right, lBegin + len, rBegin);
}
else
{
return Compare(left, right, lBegin, rBegin + len);
}
}
}
public class Solution {
public string LargestNumber(int[] nums) {
var sb = new StringBuilder();
var strs = nums.Select(n => n.ToString(CultureInfo.InvariantCulture)).OrderByDescending(s => s, new Comparer());
var nonZeroOccurred = false;
foreach (var str in strs)
{
if (!nonZeroOccurred && str == "0") continue;
sb.Append(str);
nonZeroOccurred = true;
}
return sb.Length == 0 ? "0" : sb.ToString();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。