我在LeetCode尝试了一个问题,似乎几乎是这样。 这就是我迄今为止所做的工作:Fiddle 和问题链接——30. Substring with Connation of Alls Words/。 下面是我迄今为止所做的法典:
static IList < int > FindSubstring(string s, string[] words) {
var list = new List < IList < string >> ();
DoPermutation(words, 0, words.Length - 1, list);
return TrackIndexes(s, list);
}
static IList < IList < string >> DoPermutation(string[] str, int start, int end, IList < IList < string >> list) {
if (start == end) {
list.Add(new List < string > (str));
} else {
for (var i = start; i <= end; i++) {
Swap(ref str[start], ref str[i]);
DoPermutation(str, start + 1, end, list);
Swap(ref str[start], ref str[i]);
}
}
return list;
}
static void Swap(ref string a, ref string b) {
var temp = a;
a = b;
b = temp;
}
static List < int > TrackIndexes(string pattern, IList < IList < string >> aLst) {
int count = 0;
List < string > strings;
List < int > indexes = new List < int > ();
foreach(var item in aLst) {
string str = "";
strings = new List < string > {
String.Concat(item)
};
foreach(var list in item) {
str += list;
if (str.Length == strings[0].Length && pattern.Contains(str)) {
indexes.AddRange(AllIndexesOf(pattern, str));
count += 1;
}
}
}
indexes.Sort();
return indexes.Distinct().ToList();
}
public static int[] AllIndexesOf(string str, string substr, bool ignoreCase = false)
{
if (string.IsNullOrWhiteSpace(str) || string.IsNullOrWhiteSpace(substr))
{
throw new ArgumentException("String or substring is not specified.");
}
var indexes = new List<int>();
int index = 0;
while ((index = str.IndexOf(substr, index, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) != -1)
{
indexes.Add(index++);
}
return indexes.ToArray();
}
我提出的问题是:
s = "pjzkrkevzztxductzzxmxsvwjkxpvukmfjywwetvfnujhweiybwvvsrfequzkhossmootkmyxgjgfordrpapjuunmqnxxdrqrfgkrsjqbszgiqlcfnrpjlcwdrvbumtotzylshdvccdmsqoadfrpsvnwpizlwszrtyclhgilklydbmfhuywotjmktnwrfvizvnmfvvqfiokkdprznnnjycttprkxpuykhmpchiksyucbmtabiqkisgbhxngmhezrrqvayfsxauampdpxtafniiwfvdufhtwajrbkxtjzqjnfocdhekumttuqwovfjrgulhekcpjszyynadxhnttgmnxkduqmmyhzfnjhducesctufqbumxbamalqudeibljgbspeotkgvddcwgxidaiqcvgwykhbysjzlzfbupkqunuqtraxrlptivshhbihtsigtpipguhbhctcvubnhqipncyxfjebdnjyetnlnvmuxhzsdahkrscewabejifmxombiamxvauuitoltyymsarqcuuoezcbqpdaprxmsrickwpgwpsoplhugbikbkotzrtqkscekkgwjycfnvwfgdzogjzjvpcvixnsqsxacfwndzvrwrycwxrcismdhqapoojegggkocyrdtkzmiekhxoppctytvphjynrhtcvxcobxbcjjivtfjiwmduhzjokkbctweqtigwfhzorjlkpuuliaipbtfldinyetoybvugevwvhhhweejogrghllsouipabfafcxnhukcbtmxzshoyyufjhzadhrelweszbfgwpkzlwxkogyogutscvuhcllphshivnoteztpxsaoaacgxyaztuixhunrowzljqfqrahosheukhahhbiaxqzfmmwcjxountkevsvpbzjnilwpoermxrtlfroqoclexxisrdhvfsindffslyekrzwzqkpeocilatftymodgztjgybtyheqgcpwogdcjlnlesefgvimwbxcbzvaibspdjnrpqtyeilkcspknyylbwndvkffmzuriilxagyerjptbgeqgebiaqnvdubrtxibhvakcyotkfonmseszhczapxdlauexehhaireihxsplgdgmxfvaevrbadbwjbdrkfbbjjkgcztkcbwagtcnrtqryuqixtzhaakjlurnumzyovawrcjiwabuwretmdamfkxrgqgcdgbrdbnugzecbgyxxdqmisaqcyjkqrntxqmdrczxbebemcblftxplafnyoxqimkhcykwamvdsxjezkpgdpvopddptdfbprjustquhlazkjfluxrzopqdstulybnqvyknrchbphcarknnhhovweaqawdyxsqsqahkepluypwrzjegqtdoxfgzdkydeoxvrfhxusrujnmjzqrrlxglcmkiykldbiasnhrjbjekystzilrwkzhontwmehrfsrzfaqrbbxncphbzuuxeteshyrveamjsfiaharkcqxefghgceeixkdgkuboupxnwhnfigpkwnqdvzlydpidcljmflbccarbiegsmweklwngvygbqpescpeichmfidgsjmkvkofvkuehsmkkbocgejoiqcnafvuokelwuqsgkyoekaroptuvekfvmtxtqshcwsztkrzwrpabqrrhnlerxjojemcxel",
words = ["dhvf","sind","ffsl","yekr","zwzq","kpeo","cila","tfty","modg","ztjg","ybty","heqg","cpwo","gdcj","lnle","sefg","vimw","bxcb"]
守则一在<代码> 单程式代码>方法中列出了可能的改动清单,对于上述投入,该编码生成了从记忆错误中提取的示意图清单。 我不敢肯定,如果能够用我所拥有的法典来改变任何东西。
现在,在180个测试案例中,我的代码为151个。 是否在利用现行法典避开记忆例外,或者我必须重新思考这一问题?
<>>目标>: 守则的主要目的是为护卫清单制定可能的调和,使之与按护卫模式标示的护卫相匹配。