题目描述
示例
提示
class Solution {
public int numJewelsInStones(String jewels, String stones) {
int count = 0;
for (int i = 0; i < stones.length(); i++) {
for (int j = 0; j < jewels.length(); j++) {
if (stones.charAt(i)==jewels.charAt(j)) {
count++;
break;
}
}
}
return count;
}
}
知识点:
String.charAt()方法返回指定索引处的char值。索引的范围是从0到length()-1
例如:str.charAt(0)检索str中的第一个字符,str.charAt(str.length()-1)检索最后一个字符