[LeetCode] 771. Jewels and Stones (Java)
https://leetcode.com/problems/jewels-and-stones/
Solution
class Solution {
static int numJewelsInStones(String jewels, String stones) {
int answer = 0;
for (int i = 0; i < stones.length(); i++) {
for (int j = 0; j < jewels.length(); j++) {
if (jewels.charAt(j) == stones.charAt(i)) {
answer++;
}
}
}
return answer;
}
public static void main(String[] args) {
System.out.println(numJewelsInStones("aA", "aAAbbbb"));
System.out.print(numJewelsInStones("z", "ZZ"));
}
}
Leave a comment