출처 : https://leetcode.com/problems/jewels-and-stones/
You're given strings jewels
representing the types of stones that are jewels, and stones
representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.
Letters are case sensitive, so "a"
is considered a different type of stone from "A"
.
class Solution {
public int numJewelsInStones(String jewels, String stones) {
int count = 0;
String[] j = jewels.split("");
String[] s = stones.split("");
for (int a = 0; a < s.length; a++) {
for (int b = 0; b < j.length; b++) {
if (s[a].equals(j[b])) count++;
}
}
return count;
}
}