zoukankan      html  css  js  c++  java
  • 255. Multi-string search

    255. Multi-string search

    中文English

    给出一个源字符串sourceString和一个目标字符串数组targetStrings,判断目标字符串数组中的每一个字符串是否是源字符串的子串

    样例

    样例 1:

    输入: sourceString = "abc" ,targetStrings = ["ab","cd"]
    输出: [true, false]
    

    样例 2:

    输入: sourceString = "lintcode" ,targetStrings = ["lint","code","codes"]
    输出: [true,true,false]	
    

    注意事项

    len(sourceString) <= 1000
    sum(len(targetStrings[i])) <= 1000

     
     
    输入测试数据 (每行一个参数)如何理解测试数据?
    class Solution:
        """
        @param sourceString: a string
        @param targetStrings: a string array
        @return: Returns a bool array indicating whether each string in targetStrings is a substring of the sourceString
        """
        def whetherStringsAreSubstrings(self, sourceString, targetStrings):
            # write your code here
            #子串,连续的字符串
            
            res = []
            length = len(sourceString)
            
            #主方法
            for target in targetStrings:
                if len(target) > length:
                    res.append(False)
                    continue
                
                #判断
                flag = False 
                l = len(target)
                for j in range(length - l + 1):
                    if sourceString[j: j + l] == target:
                        flag = True
                        break
                    
                res.append(flag)
            
            return res
  • 相关阅读:
    luogu 3388 【模板】割点(割顶)
    bzoj 3624 免费道路
    bzoj 1179 Atm
    bzoj 2428 均分数据
    luogu 4429 染色
    luogu 4427 求和
    luogu 1121 环状最大两段子段和
    hdu 4777 Queue
    hdu 5492 Find a path
    hdu 5441 Travel
  • 原文地址:https://www.cnblogs.com/yunxintryyoubest/p/13283668.html
Copyright © 2011-2022 走看看