leetcode 1078 Occurrences After Bigram
lc1078 Occurrences After Bigram
trim().split()将原字符串转换成words数组
依次匹配first和second,若两者都能匹配上,则下一个单词为third,将其加入List<String> res
返回 res.toArray(new String[0])
class Solution {
public String[] findOcurrences(String text, String first, String second) {
String[] textPlus = text.trim().split(" ");
List<String> res = new ArrayList();
if(textPlus.length < 3 || first.length() == 0 || second.length() == 0)
return new String[0];
for(int i=0; i<textPlus.length-2; i++){
if(textPlus[i].equals(first) && textPlus[i+1].equals(second)){
res.add(textPlus[i+2]);
}
}
return res.toArray(new String[0]);
}
}
leetcode 1078 Occurrences After Bigram的更多相关文章
- 【Leetcode_easy】1078. Occurrences After Bigram
problem 1078. Occurrences After Bigram 题意 solution: class Solution { public: vector<string> fi ...
- 【leetcode】1078. Occurrences After Bigram
题目如下: Given words first and second, consider occurrences in some text of the form "first second ...
- LeetCode.1078-两词出现后的单词(Occurrences After Bigram)
这是小川的第392次更新,第422篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第254题(顺位题号是1078).给出单词first和单词second,以"fi ...
- 【LeetCode】5083. Occurrences After Bigram 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串分割遍历 日期 题目地址:https://le ...
- [Swift]LeetCode1078. Bigram 分词 | Occurrences After Bigram
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- LeetCode.1207-唯一的元素出现次数(Unique Number of Occurrences)
这是小川的第次更新,第篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第269题(顺位题号是1207).给定一个整数数组arr,当且仅当该数组中每个元素的出现次数唯一时,返回tr ...
- 【leetcode】1207. Unique Number of Occurrences
题目如下: Given an array of integers arr, write a function that returns true if and only if the number o ...
- [LeetCode] Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
随机推荐
- SQL Server Management Studio 的账号密码
使用“Windows身份验证”方式无法登陆 使用“SQL Server身份验证” 方式无法登陆 解决办法:关闭当前所有服务.通过[Microsoft SQL Server 2008]|[配置工具]|[ ...
- day15 python-03 列表,元组,字典
Python之路,Day3 = Python基础3 注: extend: 拼接 enumerate:打印序号,返回两个值 模块的简单使用 sys模块 #!/usr/bin/env python #这句 ...
- 概率dp——cf518D
通过最后的概率求最终的期望 #include<bits/stdc++.h> using namespace std; ; double p,dp[maxn][maxn]; int n,t; ...
- golang中net/http包的简单使用
一.介绍 http包提供了http客户端和服务端的实现 Get,Head,Post和PostForm函数发出http.https的请求 程序在使用完回复后必须关闭回复的主体 #简单的访问网站,由于没有 ...
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- 初识OpenCV-Python - 004: Trackbar as the color palette
此次学习了如何用OpenCV建立一个色调盘.其中会用到cv2.getTrackbarPos(), cv2.createTrackbar()函数. code: import cv2import nump ...
- LINUX挂接移动硬盘
对linux系统而言,USB接口的移动硬盘是当作SCSI设备对待的.插入移动硬盘之前,应先用fdisk –l 或 more /proc/partitions查看系统的硬盘和硬盘分区情况. [root ...
- MATLAB 去掉数组里面不要的元素
trainfinger=1 testingfinger=(1:8); testingfinger = testingfinger(~ismember(testingfinger,trainfinger ...
- 用在 AMD64 上 aria2_1.33.1-1_amd64.deb 的下载页面
用在 AMD64 上 aria2_1.33.1-1_amd64.deb 的下载页面 如果您正在运行 Ubuntu,请尽量使用像 aptitude 或者 synaptic 一样的软件包管理器,代替人工手 ...
- C++: inheritance
公有继承(public).私有继承(private).保护继承(protected)是常用的三种继承方式. 1. 公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时, ...