题目如下:

Given words 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.

For each such occurrence, add "third" to the answer, and return the answer.

Example 1:

Input: text = "alice is a good girl she is a good student", first = "a", second = "good"
Output: ["girl","student"]

Example 2:

Input: text = "we will we will rock you", first = "we", second = "will"
Output: ["we","rock"]

Note:

  1. 1 <= text.length <= 1000
  2. text consists of space separated words, where each word consists of lowercase English letters.
  3. 1 <= first.length, second.length <= 10
  4. first and second consist of lowercase English letters.

解题思路:非常简单的题目,先把text分割成数组形式,然后遍历text,如果text[i] = first 并且text[i+1] = second,那么text[i+2]就是一个answer。

代码如下:

class Solution(object):
def findOcurrences(self, text, first, second):
"""
:type text: str
:type first: str
:type second: str
:rtype: List[str]
"""
text = text.split(' ')
res = []
for i in range(len(text) - 2):
if text[i] == first and text[i+1] == second:
res.append(text[i+2])
return res

【leetcode】1078. Occurrences After Bigram的更多相关文章

  1. 【Leetcode_easy】1078. Occurrences After Bigram

    problem 1078. Occurrences After Bigram 题意 solution: class Solution { public: vector<string> fi ...

  2. 【LeetCode】5083. Occurrences After Bigram 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串分割遍历 日期 题目地址:https://le ...

  3. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

  4. 【LeetCode】722. Remove Comments 解题报告(Python)

    [LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...

  5. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  6. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  7. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  8. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  9. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

随机推荐

  1. C#中查找或结束程序域中的主、子进程

    有时候,我们的程序需要启动一些子进程,如嵌入的图形程序. 当启动一个进程后,获得这个进程信息Process,然后其内部在某个时刻启动了一个子进程,这个时候就涉及程序域和进程树的概念.当我们通过非正常操 ...

  2. Flask中的实例化配置

    也就是在app=Flask(__name__)括号中的参数 1.static_folder = 'static', # 静态文件目录的路径 默认当前项目中的static目录 2.static_url_ ...

  3. firefox的group群组功能很好!

    ================================ /usr/share/themes中有一些主题,包括: adwaita: 阿德维塔, 不二论 anaconda等等. 计算机环境: f ...

  4. DelayQueue 源码分析

    DelayQueue DelayQueue 是基于 PriorityQueue 实现的线程安全的无界优先级阻塞队列, 队列的头部元素必须在超时后才能移除,元素必须实现 Delayed 接口. 创建实例 ...

  5. linux环境常用分析日志的几个命令

    前言: 分析日志是定位问题的常用手段,但实际线上可能有大量日志,掌握一些常见查看.过滤和分析日志的命令能起到事半功倍的效果.下面列出工作中最常用的一些命令,可在具体使用是查看,尝试使用.实际使用使往往 ...

  6. Altium Designer chapter8总结

    元件库操作中需要注意如下: (1)原理图库:主要分三部分来完成(绘制元件的符号轮廓.放置元件引脚.设计规则检查). (2)多子件原理图库:操作与原理图库基本相同,就是新建part. (3)PCB封装库 ...

  7. Struts2入门1

    Struts2的概述: Struts2是应用在Javaee三层结构中的web层.Struts2是在Struts1和webwork的基础之上发展的全新的框架.在没有使用Struts2之前,进行web层的 ...

  8. SQL Puzzle

    1. 按条件分块取数据 有表A(CD),数据为 要求:当有CD为0的记录时,取得结果为0, 当表中没有CD=0的记录时,取得的结果为1,2,3(将CD<>0的记录都取出来) 可行SQL脚本 ...

  9. XMind8激活为Pro教程 - Windows&Mac

    本教程用于激活XMind(思维导图制作软件),仅限于个人学习使用. 目前本人激活的版本是xmind8-up6版本,其他更高版本不保证能适用. Windows步骤: 1.英文官网下载客户端并安装(不能用 ...

  10. [Python3] 012 元组:list,我们不一样!

    目录 0. 元组的独白 1. 元组的创建 2. 元组的特性 (1) 概述 (2) 少废话,上例子 1) 索引 2) 分片 3) 序列运算 4) 成员检测 3. 元组的遍历 (1) 简单总结 (2) 少 ...