找出字符串数组中所有最长的字符串

    public string[] LongestWords(string[] strs)
    {
        List<string> res = new List<string>();
        int length = 0;
        for (int i = 0; i < strs.Length; i++)
        {
            if (strs[i].Length >= length)
            {
                if (strs[i].Length > length)
                {
                    length = strs[i].Length;
                    res.Clear();
                }
                res.Add(strs[i]);
            }
        }
        return res.ToArray();
    }

猜你喜欢

转载自blog.csdn.net/wenbooboo/article/details/80198858