大家好,我是毛毛。ヾ(´∀ ˋ)ノ
来到30天的最後一天解题Day啦~
Given two strings first
and second
, consider occurrences in some text of the form "first second third"
, where second
comes immediately after first
, and third
comes immediately after second
.
Return an array of all the words third
for each occurrence of "first second third"
.
Input: text = "alice is a good girl she is a good student", first = "a", second = "good"
Output: ["girl","student"]
Input: text = "we will we will rock you", first = "we", second = "will"
Output: ["we","rock"]
1 <= text.length <= 1000
text
consists of lowercase English letters and spaces.text
a separated by a single space.1 <= first.length, second.length <= 10
first
and second
consist of lowercase English letters.首先先简单的翻译一下题目
给一个字串句子,然後给first
跟second
两个字串,要找到所有符合条件的third
字串,条件就是first下一个要接着second,second下一个要接third。
作法大致上是这样
class Solution:
def findOcurrences(self, text: str, first: str, second: str) -> List[str]:
list_text = text.split(" ")
ans = []
for index in range(len(list_text)):
if list_text[index] == first:
if index+1 <= len(list_text)-1 and list_text[index+1] == second:
if index+2 <= len(list_text)-1:
ans.append(list_text[index+2])
return ans
大家下次见
<<: Youtube API - 凡事趁早没有那麽多来日方长(总结)
...
前言 Tableau 是多个软件的通称,我们初学在进行 BI 分析时,最常会用到其中的三种,分别为 ...
俗话说人要衣装,佛要金装,我们的 vim 也得要有漂亮的外观。今天就让我们来看看如何调教调整 vim...
前言 我明明记得我昨天就PO==,结果今天看到通知才发现被中断了,算了哈哈,那我这边就慢慢PO好了,...
今天来实作身分验证的部分,笔者此前是用 ASP.NET Core Web API 搭配 Blazor...