Substring with Concatenation of All Words
来源:互联网 发布:百锐腾软件 编辑:程序博客网 时间:2024/06/16 08:29
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.
For example, given:
S: "barfoothefoobarman"
L: ["foo", "bar"]
You should return the indices: [0,9]
.
(order does not matter).
class Solution: # @param S, a string # @param L, a list of string # @return a list of integer def findSubstring(self, S, L): ret=[] step,lenL,lenS = len(L[0]),len(L),len(S) i=0 while i+step*lenL-1<lenS: flag=True listS=[S[k : k + step] for k in xrange(i, i + lenL * step, step)] for item in L: if item in listS: listS.remove(item) else: flag=False break if flag: ret.append(i) i=i+1 return ret
0 0
- LeetCode: Substring with Concatenation of All Words
- LeetCode : Substring with Concatenation of All Words
- LeetCode29: Substring with Concatenation of All Words
- [Leetcode] Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- [LeetCode]Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- LeetCode-Substring with Concatenation of All Words
- [LeetCode] Substring with Concatenation of All Words
- 26 - Substring with Concatenation of All Words
- LeetCode:Substring with Concatenation of All Words
- Leetcode: Substring with Concatenation of All Words
- [LeetCode] Substring with Concatenation of All Words
- leetcode Substring with Concatenation of All Words
- leetcode Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- LeetCode Substring with Concatenation of All Words
- WebService介绍优缺点吧。
- Xcode6模拟器iOS8键盘出不来问题
- java.lang.UnsatisfiedLinkError解决方法汇集(转载)
- Java设计模式及示例代码
- Android学习资料
- Substring with Concatenation of All Words
- 值已被互换
- android sqlite3 常用命令
- Android开发之高仿微信界面(1)
- Java中的堆和栈
- Impala与Hive的比较
- JS学习笔记
- game.py
- memcpy源码