LeetCode-30.串联所有单词的子串

LeetCode-30.串联所有单词的子串_第1张图片

地址:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/

思路:用无序map保留words,遍历字符串s,同时按照words中单词的长度分段处理字符串s,这样可以不必每次清空map

Code:

class Solution {
public:
    vector findSubstring(string s, vector& words) {
        vector res;
        unordered_map imap,pi;
        int n=words.size(),m=0;
        if(n)    m=words[0].size();
        if(!s.size()||!m)  return res;
        for(int i=0;i

 

你可能感兴趣的:(LeetCode)