这是一个创建于 2590 天前的主题,其中的信息可能已经有所发展或是发生改变。
用 leetcode 写的第一道题是 771 宝石与石头
这么写的
java
public int numJewelsInStones(String J, String S) {
int count = 0;
char[] jstOne= J.toCharArray();
char[] sstOne= S.toCharArray();
for (char j : jstne) {
for (char s : sstone) {
if (s == j) {
count++;
}
}
}
return count;
}
能够执行通过,换成正则这么写
java
char[] jstOne= J.toCharArray();
for (char j : jstone) {
String regex = String .valueOf(j);
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern .matcher(S);
while (matcher.find()) {
count++;
}
}
不能执行,返回错误 error: cannot find symbol: class Pattern
3 条回复 2018-12-19 17:11:26 +08:00  | | 1 backfrw 2018-11-23 15:57:55 +08:00 另外,发帖怎么写代码片啊? 都是新手问题,谢谢大家 |