【leetcode】1078. Occurrences After Bigram
题目如下:
Given words
firstandsecond, consider occurrences in sometextof the form "first second third", wheresecondcomes immediately afterfirst, andthirdcomes immediately aftersecond.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 <= text.length <= 1000textconsists of space separated words, where each word consists of lowercase English letters.1 <= first.length, second.length <= 10firstandsecondconsist 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的更多相关文章
- 【Leetcode_easy】1078. Occurrences After Bigram
problem 1078. Occurrences After Bigram 题意 solution: class Solution { public: vector<string> fi ...
- 【LeetCode】5083. Occurrences After Bigram 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串分割遍历 日期 题目地址:https://le ...
- 【LeetCode】481. Magical String 解题报告(Python)
[LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...
- 【LeetCode】722. Remove Comments 解题报告(Python)
[LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- 高通 8x26 andorid light sensor(TSL258x) 开发【转】
本文转载自:http://www.voidcn.com/blog/u012296694/article/p-1669831.html 前言 8926平台的sensor架构与之前的平台完全不同,实际上已 ...
- 消息队列之 ActiveMQ
简介 ActiveMQ 特点 ActiveMQ 是由 Apache 出品的一款开源消息中间件,旨在为应用程序提供高效.可扩展.稳定.安全的企业级消息通信. 它的设计目标是提供标准的.面向消息的.多语言 ...
- nodeName,nodeValue未知 xml 入库方案 The ElementTree iterparse Function
import xml.etree.ElementTree as ET from lxml.html import * from xmljson import badgerfish as bf from ...
- MyBatis逆向工程去除表名前缀
https://www.jianshu.com/p/e09d2370b796 https://blog.csdn.net/baidu_16757561/article/details/75071476 ...
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_01 Collection集合_4_Iterator接口介绍
collection集合中是没有索引的,不能使用普通的循环来便利它. 也是在util的包中 先判断集合中有没有元素 有元素就取出来,用next方法 使用接口来接受一个实现类,这就是多态
- 阿里云DNS api接口 shell 更改DNS解析
可定时任务检查域名解析,调用alidns.sh更新DNS解析 #!/bin/bash # alidns.sh #https://www.cnblogs.com/elvi/p/11663910.html ...
- linux下vscode备忘
vscode如何自定义,如何方便地编写c/c++vscode支持vim.sublime快捷键,在设置->keymap可以安装相应插件vscode默认的快捷键支持自定义,打开keyboard sh ...
- 【ABAP系列】SAP ABAP的事件执行顺序
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP的事件执行顺序 ...
- spring-data-elasticsearch使用出现的一些小问题
问题一failed to load elasticsearch nodes : org.elasticsearch.index.mapper.MapperParsingException: No ty ...
- 安装mysql8.0.17时候报错1251-Client does not support authentication protocol requested by server; consider upgrading MySQL client
当mysql数据库安装时候选择的是加密密码时候,用navicat连接时候报错1521,这时候可以cmd之后登陆mysql执行下列代码就可以了 代码: mysql> alter user root ...