日期:2014-05-17 浏览次数:20922 次
var arr = new int[]{1,2,3,4,5,6,7,8,9,80,86,47,203,405,411};
var sort_arr = arr.OrderBy(x => x).ToArray();
var dv = (from n in Enumerable.Range(0, arr.Length - 1)
let minute = sort_arr[n + 1] - sort_arr[n]
select minute).Min();
var result = from n in Enumerable.Range(0, arr.Length - 1)
where sort_arr[n + 1] - sort_arr[n] == dv
------解决方案--------------------
n>0 && sort_arr[n]-sort_arr[n-1]== dv
select sort_arr[n];
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
bool stop = false;
var data = (new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 80, 86, 47, 203, 405, 411 }).OrderBy(x => x);
List<int> r = new List<int>();
int min = data.Skip(1).First() - data.First();
r.Add(data.First());
foreach (var item in data.Take(data.Count() - 1).Zip(data.Skip(1), (x, y) => new { x, y }))
{
if (item.y - item.x == min && !stop)
{
r.Add(item.y);
}
else
{
stop = true;
&nb