LeetCode - Algorithms - 771. Jewels and Stones

Problem

771. Jewels and Stones

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public int numJewelsInStones(String jewels, String stones) {
Set<Character> j = new HashSet<Character>();
for(int i=0;i<jewels.length();i++)
j.add(jewels.charAt(i));
int n = 0;
for(int i=0;i<stones.length();i++)
if (j.contains(stones.charAt(i)))
n++;
return n;
}
}

Submission Detail

  • 255 / 255 test cases passed.
  • Runtime: 1 ms, faster than 64.92% of Java online submissions for Jewels and Stones.
  • Memory Usage: 37 MB, less than 89.30% of Java online submissions for Jewels and Stones.