771. Jewels and Stones 珠寶與石頭
❀ Origin
Problem
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" |
Example 2
1 | Input: J = "z", S = "ZZ" |
❀ 翻譯
問題
有一字串 J 代表寶石的種類, 字串 S 代表你擁有的石頭.
字串 S 的每一個字元都代表著你有的一個那種石頭.
你想要知道你的石頭裡有幾個是寶石.
字串 J 的每個字母都保證不同, 而且 J 與 S 的每個字元都保證是字母.
字母有區分大小寫, 所以 “a” 被認定為與 “A” 是不同類型的石頭.
❀ Solution
JavaScript
1 | /** |
Golang
1 | func numJewelsInStones(J string, S string) int { |