c# leetcode 30 还在写(未完成)

首先:说一下我对这道题的思路

public static IList<int> FindSubstring(string s, string[] words)
        {
            //0、返回值
            IList<int> res= new List<int>();
            //1、求长度
            int wordslengh = words.Length;//求words单词个数
            int wordss = words[0].Length;//求words里的数量
            //2、求组合的长度
            int newlenth = wordss * wordslengh;
            //3、将所有排序组合的字符串放到dic中   offbar/baroff
            var dic = new Dictionary<int, string>();
            for (int j = 0; j < words.Length; j++)
            {
                dic.Add(j,words[j]);
            }
            int i = 0;
            while (i<=s.Length-wordss)
            {
                if (s.Substring(i, wordss)==dic[i])
                {
                    res.Add(i);
                }
                i++;
            }
            return res;
        }

猜你喜欢

转载自blog.csdn.net/us2019/article/details/86499896