数组排序【难度:2级】:
答案1:
using System.Linq;
public class Kata
{
public static int NthSmallest(int[][] arr, int n)
{
return arr.SelectMany(e => e).OrderBy(e => e).ToArray()[n - 1];
}
}
答案2:
using System.Collections.Generic;
public class Kata
{
public static int NthSmallest(int[][] arr, int n)
{
var sorted = new List<int>();
foreach (var a in arr)
{
sorted = Merge(sorted, a);
}
return sorted[n - 1];
}
public static List<int> Merge(List<int> sorted, int[] input)
{
var output = new List<int>();
int indexSorted = 0;
int indexInput = 0;
while (indexSorted < sorted.Count && indexInput < input.Length)
{