Leetcode30與所有單詞相關聯的字串。

2021-08-20 02:28:37 字數 518 閱讀 9276

題目:定乙個字串 s 和一些長度相同的單詞 words。在s 中找出可以恰好串聯 words 中所有單詞的子串的起始位置。

注意子串要與 words 中的單詞完全匹配,中間不能有其他字元,但不需要考慮 words 中單詞串聯的順序。

public static listfindsubstring(string s, string words) 

int n=s.length(),num=words.length,len=words[0].length();

for(int i=0;i=n-num*len+1的時候 所剩字元已小於要求的字串 長度,結束

mapseen=new hashmap<>();

int j=0;

while(jcounts.get(word))

break;

}else

j++;

}if(j==num)

}return indexes;

}

Leetcode 30 與所有單詞相關聯的字串

題目描述 給定乙個字串 s 和一些長度相同的單詞 words。在 s 中找出可以恰好串聯 words 中所有單詞的子串的起始位置。注意子串要與 words 中的單詞完全匹配,中間不能有其他字元,但不需要考慮 words 中單詞串聯的順序。示例 1 輸入 s barfoothefoobarman wo...

LeetCode 30 與所有單詞相關聯的字串

描述 給定乙個字串 s 和一些長度相同的單詞 words。在 s 中找出可以恰好串聯 words 中所有單詞的子串的起始位置。注意子串要與 words 中的單詞完全匹配,中間不能有其他字元,但不需要考慮 words 中單詞串聯的順序。示例 1 輸入 s barfoothefoobarman word...

leetcode30 與所有單詞相關聯的字串

leetcode.0030 與所有單詞相關聯的字串 給定乙個字串 s 和一些長度相同的單詞 words。在 s 中找出可以恰好串聯 words 中所有單詞的子串的起始位置。注意子串要與 words 中的單詞完全匹配,中間不能有其他字元,但不需要考慮 words 中單詞串聯的順序。示例1 輸入 s b...