1. Jewels and Stones
class Solution:
def numJewelsInStones(self, J, S):
"""
:type J: str
:type S: str
:rtype: int
"""
res = 0
for s in S:
if s in J:
res += 1
return res
更優解法:
def numJewelsInStones(self, J, S): return sum(map(J.count, S))
def numJewelsInStones(self, J, S):
return sum(s in J for s in S)
相關推薦
1. Jewels and Stones
class Solution: def numJewelsInStones(self, J, S): """ :type J: str :type S: str :rtype: int
1/100. Jewels and Stones
class Solution: def numJewelsInStones(self, J, S): """ :type J: str :type S: str :rtype: int """
771. Jewels and Stones 珠寶和石頭
rep sid enum nes mos rom font most ret You‘re given strings J representing the types of stones that are jewels, and S representing the st
[LeetCode&Python] Problem 771: Jewels and Stones
leetcode diff The letter cas light sid sel nbsp You‘re given strings J representing the types of stones that are jewels, and S representi
【leetcode】771. Jewels and Stones
一、題目描述 You're given strings J representing the types of stones that are jewels, and S representing the stones you have.&nb
(java)leetcode771 寶石與石頭(Jewels and Stones)
題目描述: 給定字串J 代表石頭中寶石的型別,和字串 S代表你擁有的石頭。 S 中每個字元代表了一種你擁有的石頭的型別,你想知道你擁有的石頭中有多少是寶石。 J 中的字母不重複,J 和 S中的所有字元都是字母。字母區分
Leetcode771.Jewels and Stones寶石與石頭
給定字串J 代表石頭中寶石的型別,和字串 S代表你擁有的石頭。 S 中每個字元代表了一種你擁有的石頭的型別,你想知道你擁有的石頭中有多少是寶石。 J 中的字母不重複,J 和 S中的所有字元都是字母。字母區分大小寫,因此"a
【部落格搬家舊文】leetcode 771. Jewels and Stones
今天開通了部落格園 ,之前的部落格就不用了。之後再陸陸續續把之前的博文重新放到這裡來。有標題這個tag的都是搬運的舊部落格的文章。希望在這裡是個新的開始,嘻嘻。 import java.util.Scanner; class Solution { public
【博客搬家舊文】leetcode 771. Jewels and Stones
inf nbsp 嘻嘻 用戶輸入 pan spa 重新 ring expec 今天開通了博客園 ,之前的博客就不用了。之後再陸陸續續把之前的博文重新放到這裏來。有標題這個tag的都是搬運的舊博客的文章。希望在這裏是個新的開始,嘻嘻。 import java.
LeetCode-771. Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each charac
LC 771. Jewels and Stones
1.題目 You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each
【leetcode】771.Jewels and Stones 用python實現
題目描述 You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each charact
LeetCode 771 Jewels and Stones 寶石與石頭
解法一: class Solution { public: int numJewelsInStones(string J, string S) { int count=0; for(int i=0;i<J.size();++i)
leetcode771 寶石與石頭(Jewels and Stones)
題目描述: 給定字串J 代表石頭中寶石的型別,和字串 S代表你擁有的石頭。 S 中每個字元代表了一種你擁有的石頭的型別,你想知道你擁有的石頭中有多少是寶石。 J 中的字母不重複,J 和 S中的所有字
leetcode 771: Jewels and Stones
題目: You're given strings J representing the types of stones that are jewels, and Srepresenting the stones you have. Each character in S
leetcode 771. Jewels and Stones
771. Jewels and Stones You're given strings J representing the types of stones that are jewels, and Srepresenting the stones you have. E
【LeetCode】771(Java)Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S
771. Jewels and Stones - Easy
You're given strings J representing the types of stones that are jewels, and Srepresenting the stones you have. Each character
LeetCode771:Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each charac
LeetCode-Jewels and Stones java 寶石計算
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 yo