Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created June 2, 2019 22:28
Show Gist options
  • Select an option

  • Save brianmed/4b2bdb7185b048c5e067d0cfc4324411 to your computer and use it in GitHub Desktop.

Select an option

Save brianmed/4b2bdb7185b048c5e067d0cfc4324411 to your computer and use it in GitHub Desktop.
LexicographSort Integer List
using System;
using System.Collections.Generic;
using System.Linq;
namespace LexicographicSortIntegerList
{
class Program
{
static void Main(string[] args)
{
// echo "41 4\n" | dotnet run (Output 441)
List<int> digits = Console.ReadLine()
.Split(' ')
.Select(x => Int32.Parse(x))
.ToList();
digits.Sort((a, b) => {
int left = Int32.Parse(a.ToString() + b.ToString());
int right = Int32.Parse(b.ToString() + a.ToString());
return right.CompareTo(left);
});
Console.WriteLine(String.Join("", digits));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment