an = new ArrayList<>(); int n = 0; for (int i = 0; i < words.le_bigram分词matlab">
赞
踩
public class Solution {
public static String[] findOcurrences(String text, String first, String second) {
String[] words = text.split(" ");// 先拆成单个单词
List<String> an = new ArrayList<>();
int n = 0;
for (int i = 0; i < words.length - 2; i++) {// -2,排除最后两个单词
if (words[i].equals(first) && words[i + 1].equals(second)) {
an.add(words[i + 2]);
n++;
}
}
return an.toArray(new String[an.size()]);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。