Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Jewels and Stones

XPChallenge Points: 10
levelLevel: Easy

You are given two strings:
precious → representing the types of stones that are considered precious, and
stones → representing all the stones you currently have.
Each character in stones represents one stone.
Your task is to determine how many stones you own are precious.
Note:
Characters are case-sensitive, meaning 'a' and 'A' are treated as different stones.

Example 1:

Input: precious = "mN" stones = "nnmmMN"

Output: 3

Explanation:

Precious stones are 'm' and 'N'. In "nnmmMN", the precious stones found are 'm', 'm', and 'N' → total = 3.

Example 2:

Input: precious = "xX" stones = "xxXXxyz"

Output: 5

Explanation:

Precious stones are 'x' and 'X'. In "xxXXxyz", there are two 'x' and two 'X' → total = 4.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result