771. Jewels and Stones
Question
You’re given strings
jewels
representing the types of stones that are jewels, andstones
representing the stones you have. Each character instones
is a type of stone you have. You want to know how many of the stones you have are also jewels.Letters are case sensitive, so
"a"
is considered a different type of stone from"A"
.
Solution
数组统计,先遍历宝石,记录宝石的位置。
然后遍历石头,如果对应的位置已被记录则计数加一。
Code
1 | class Solution { |
771. Jewels and Stones
https://xuanhe95.github.io/2022/06/21/771-Jewels-and-Stones/