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的更多相关文章

  1. 【Leetcode_easy】1078. Occurrences After Bigram

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

  2. 【leetcode】1078. Occurrences After Bigram

    题目如下: Given words first and second, consider occurrences in some text of the form "first second ...

  3. LeetCode.1078-两词出现后的单词(Occurrences After Bigram)

    这是小川的第392次更新,第422篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第254题(顺位题号是1078).给出单词first和单词second,以"fi ...

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

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

  5. [Swift]LeetCode1078. Bigram 分词 | Occurrences After Bigram

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. LeetCode.1207-唯一的元素出现次数(Unique Number of Occurrences)

    这是小川的第次更新,第篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第269题(顺位题号是1207).给定一个整数数组arr,当且仅当该数组中每个元素的出现次数唯一时,返回tr ...

  7. 【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 ...

  8. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  9. LeetCode 205 Isomorphic Strings

    Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...

随机推荐

  1. 莫比乌斯反演——hdu6390推公式

    /*首先要把原始化简成 k/phi[k] 的格式,然后把有关k的sigma提出来,后面就是求gcd(i,j)==k的莫比乌斯反演这里要用整除分块加下速*/#include<bits/stdc++ ...

  2. Could not open file ..\obj\sys.o: No such file or directory解决办法

    一.你的keil的安装路径以及系统用户名是否带中文字符以及一些特殊字符.二.环境变量的值存在中文或者特殊字符了,解决方法如下: 1.在C盘建立一个新的文件夹,命名为英文,如qcl2.右击"此 ...

  3. python相关软件安装流程图解——虚拟机操作——复制虚拟机主机——CentOS-7-x86_64-DVD-1810

    请先确保已经安装了虚拟机 python相关软件安装流程图解——虚拟机安装——CentOS-7-x86_64-DVD-1810——CentOS-01下载 https://www.cnblogs.com/ ...

  4. 创建文件夹、新建txt文件

    1.创建文件夹 QString myMkdir(QString path, QString floderName) //参数 path,创建的文件夹所在路径:  参数floderName,所创建的文件 ...

  5. Windows与Linux获取进程集合的方法

    Windows: List<String> tasklist=new ArrayList<String>(); try { Process process = Runtime. ...

  6. 19.SimLogin_case06

    # 使用自造的cookies登录GitHub import requests from lxml import etree str = '_octo=GH1.1.518803230.153726461 ...

  7. 使用Flume+Kafka+SparkStreaming进行实时日志分析

    每个公司想要进行数据分析或数据挖掘,收集日志.ETL都是第一步的,今天就讲一下如何实时地(准实时,每分钟分析一次)收集日志,处理日志,把处理后的记录存入Hive中,并附上完整实战代码 1. 整体架构 ...

  8. 2016.8.19上午初中部NOIP普及组比赛总结

    2016.8.19上午初中部NOIP普及组比赛总结 链接:https://jzoj.net/junior/#contest/home/1338 这次总结发得有点晚啊!我在这里解释一下, 因为浏览器的问 ...

  9. kafka数据分区的四种策略

    kafka的数据的分区 探究的是kafka的数据生产出来之后究竟落到了哪一个分区里面去了 第一种分区策略:给定了分区号,直接将数据发送到指定的分区里面去 第二种分区策略:没有给定分区号,给定数据的ke ...

  10. android 头像选择以及裁剪

    一.布局申明 <ImageView android:id="@+id/head_image" android:layout_width="80dp" an ...