Member-only story

LeetCode Challenge #3: Jewels and Stones

Victoria Lo
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:

  1. The output of this problem is an integer that represents how many characters of String J exist in String S.
  2. We have to compare each character (char) of J to each character (char) of S.
  3. 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:

  1. Initialize the output integer count…

--

--

Victoria Lo
Victoria Lo

Written by Victoria Lo

A nerd in books, tea and programming. I publish weekly on my personal blog: https://lo-victoria.com/

No responses yet