Leetcode Problem 771. Jewels and Stones

771. Jewels and Stones

Leetcode Solutions

Approach #: Hash Set

  1. Create a hash set and add all the characters from the jewels string to it.
  2. Initialize a count variable to keep track of the number of jewels found in the stones string.
  3. Iterate over each character in the stones string.
  4. For each character, check if it is present in the hash set.
  5. If the character is in the hash set, increment the count.
  6. After the iteration, return the count as the result.
UML Thumbnail

Approach #: Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...