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
  • 相关阅读:
    选择适合什么模式
    Filter做用户授权的例子
    分析LogFilter
    理解session
    XML定义用途
    web服务后台应用工作原理
    企业级应用和互联网应用的区别
    轻量级Java EE企业应用实战的目标
    软件工程期末项目总结
    软件工程之学习报告
  • 原文地址:https://www.cnblogs.com/yunxintryyoubest/p/13283668.html
Copyright © 2011-2022 走看看