【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-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Hypermesh中弹簧单元设置
1D >> springs 单元类型 CBUSH1D 单元属性 PBUSH1D
- Vue实战:音乐播放器(一) 页面效果
先看一下效果图 首页 歌单详情页 歌手列表 歌手详情页 排行页面 榜单的详情页(排序样式) 搜索页面 搜索结果 播放器内核 歌词自动滚动 播放列表 用户中心
- 当我写下Map<String,Object> map = new HashMap<>() https://www.jianshu.com/p/6b2e350e99be
当我写下Map<String,Object> map = new HashMap<>();我到底在写什么? 我什么时候会写HashMap? 一个函数同时需要返回 多种 状态的情 ...
- nvm-windows编译源码 go遇到的问题
异常: Microsoft Windows [Version 10.0.17134.1006] (c) Microsoft Corporation. All rights reserved. C:\U ...
- 【USACO18JAN】MooTube
原文链接:https://blog.csdn.net/Patrickpwq/article/details/86656456 给定一棵n个点的树(n=1e5),有边权, 两点间距离定义为两点路径上的 ...
- mysql 主从 设置
总结:1.如果是虚拟克隆mysql 请注意auto.cnf的uuid保证不一样,即删除auto.cnf 重新启动即可2.默认安装的mysql配置文件mysqld.cnf可能绑定了127.0.0.1 只 ...
- mysql树查询、递归查询
关键词:mysql树查询,mysql递归查询 转自:http://www.cnblogs.com/c-h-y/p/9420726.html 之前一直用的是Oracle,对于树形查询可以使用start ...
- Codeforces 1159F Winding polygonal line(叉积)
其实这个几何写起来还是比较方便,只用到了叉积.首先我们贪心的考虑一种情况,对于任意给定的LR串,我们起点的选择肯定是在这些点围成的凸包端点上,对于这样的起点来说,他对于L或者R都是有选择的机会,而且一 ...
- csrf原理及flask的处理方法
csrf原理及flask的处理方法 为什么需要CSRF? Flask-WTF 表单保护你免受 CSRF 威胁,你不需要有任何担心.尽管如此,如果你有不包含表单的视图,那么它们仍需要保护. 例如,由 A ...
- 加密模块hashlib
#coding=utf-8 import ConfigParser #配置文件模块 import hashlib #用于加密的模块 m = hashlib.md5() m.update(b'hello ...