其他分享
首页 > 其他分享> > Codlity(2) Min_position_value

Codlity(2) Min_position_value

作者:互联网

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Min_positive_value
{
	class Min_position_value
	{
		public static int solution(int[] A)
		{
			var positiveA = A.Where(t => t > 0).OrderBy(t => t).ToArray();


			if (positiveA.Length == 0 || positiveA[0] > 1)
			{
				return 1;
			}

			for (int i = 0; i < positiveA.Length; i++)
			{
				if (i + 1 == positiveA.Length)
					return positiveA[i] + 1;

				if (positiveA[i + 1] - positiveA[i] > 1)
				{
					return positiveA[i] + 1;
				}
			}

			throw new Exception("this should not exec");
		}
	}
}

  

标签:return,Min,int,Codlity,positiveA,System,value,position,using
来源: https://www.cnblogs.com/qgbo/p/14850949.html