Jewels and Stones

You are given a string jewels listing the stone types that are jewels, and a string stones listing the stones you have. Each character is one type of stone, and letters are case sensitive. Return how many of your stones are jewels.

30:00

Jewels and Stones
easy
Free written solution
Topics
Companies

You are given a string jewels listing the stone types that are jewels, and a string stones listing the stones you have. Each character is one type of stone, and letters are case sensitive. Return how many of your stones are jewels.

Example 1:
Input: {"jewels":"aA","stones":"aAAbbbb"}
Output: 3
Constraints:
  • 1≤jewels.length,stones.length≤501 \leq \text{jewels.length}, \text{stones.length} \leq 50

  • jewels and stones consist of only English letters.

  • All the characters of jewels are unique.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"jewels":"aA","stones":"aAAbbbb"}

Jewel types are "aA". Count how many of the 7 stones in "aAAbbbb" are one of them (case matters).

jewel set (0/2 types)

a
A

stones to check (7)

▼

a

0

▼

A

1

▼

A

2

▼

b

3

▼

b

4

▼

b

5

▼

b

6

treasure · count = 0

plain stones · 0

Variables
VariableValue
jewelsaA
stonesaAAbbbb
DepthFunction Call
Stack empty
0/11