Member-only story
LeetCode Challenge #3: Jewels and Stones
2 min readMay 22, 2020
Problem Statement
You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so “a” is considered a different type of stone from “A”.
Example 1:
Input: J = "aA", S = "aAAbbbb"
Output: 3
Example 2:
Input: J = "z", S = "ZZ"
Output: 0
Step by Step Solution
Identify patterns
After reading the problem and examples, we can conclude 3 things:
- The output of this problem is an integer that represents how many characters of String J exist in String S.
- We have to compare each character (char) of J to each character (char) of S.
- If character of J is found in S, we increase the output count by 1.
Write the Pseudocode
The following solution can be written as:
- Initialize the output integer count…