Menu
CoddyTech

Jewels and Stones

BeginnerHashingpython iconjava iconcpp iconc iconjs icon+10

You get two strings of letters. Each letter in jewels names one kind of jewel, and no letter repeats. Each letter in stones is one stone you own. Return how many of your stones are jewels. Letters are case-sensitive: "a" and "A" are different kinds.

Function

numJewelsInStones(jewels: string, stones: string) → integer
jewelsstring
the kinds of stones that count as jewels, one letter each
stonesstring
the stones you own, one letter each
Returnsinteger
the number of stones whose letter appears in jewels

Constraints

  • 1 ≤ jewels.length ≤ 52
  • 1 ≤ stones.length ≤ 104
  • Both strings contain only English letters, lowercase and uppercase.
  • The letters of jewels are all different.

Examples

Input
jewels = "rR"stones = "rubyRRr"
Output
4
Explanation
The jewel kinds are r and R. In rubyRRr the stones r, R, R and r match, while u, b and y do not, so the answer is 4.

lock icon+12 hidden tests on Submit

Reset code
def numJewelsInStones(jewels, stones):
    # Write code here
Test cases

Case 1

Case 2

Input

jewels = "rR"
stones = "rubyRRr"

Expected

4