题目:
有一个叫words的array每一项都是一个字串
每个query会有l r两个数字
要算words[l]到words[r]有几个字串头尾都是元音
答案要全部存进一个array
思路:
遍历words每一项判断头尾是不是元音
如果是就设成1不是就设成0
判断完对words做前缀和
每次query就只要words[r]-word[l-1]
python code:
Class Solution(object):
def vowelstrings(self,words,queries):
vowel={'a','e','i','o','u'}
words=[int(word[0] in vowel and word[-1] in vowel) for w in words]
ans=[]
for i in range(1,len(words)):
words[i]+=words[i-1]
return [words[r] if l==0 else words[r]-words[l-1] for l,r in queries]
剩肥肥只会用python了