CodeWars:Most digits

来源:互联网 发布:udp监听端口阻塞 编辑:程序博客网 时间:2024/06/05 19:59

题目:

我的解:

public class Kata{  public static int FindLongest(int[] number)  {    // code here    int max = number[0], maxIndex = number[0].ToString().Length;            for (int i = 1; i < number.Length; i++)            {                if (max < number[i] && maxIndex != number[i].ToString().Length)                {                    max = number[i];                    maxIndex = number[i].ToString().Length;                }                else                    continue;            }            return max;  }}

多种答案之一:

using System.Linq;public class Kata{    public static int FindLongest(int[] N)    {        return N.OrderByDescending(X => X.ToString().Length).First();    }}