1
+ ##==================================
2
+ ## Leetcode
3
+ ## Student: Vandit Jyotindra Gajjar
4
+ ## Year: 2020
5
+ ## Problem: 771
6
+ ## Problem Name: Jewels and Stones
7
+ ##===================================
8
+ #
9
+ #You're given strings J representing the types of stones that are jewels, and S representing the stones you have.
10
+ #
11
+ #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.
12
+ #
13
+ #The letters in J are guaranteed distinct, and all characters in J and S are letters.
14
+ #
15
+ #Letters are case sensitive, so "a" is considered a different type of stone from "A".
16
+ #
17
+ #Example 1:
18
+ #
19
+ #Input: J = "aA", S = "aAAbbbb"
20
+ #Output: 3
21
+ #
22
+ #Example 2:
23
+ #
24
+ #Input: J = "z", S = "ZZ"
25
+ #Output: 0
26
+
27
+ class Solution :
28
+ def numJewelsInStone (self , Jewels , Stones ):
29
+ JewelsList = [] #Initialize our empty JewelsList.
30
+ Number = 0 #Initialize our counter number.
31
+
32
+ for i in range (len (Jewels )): #Loop through Jewels
33
+ JewelsList .append (Jewels [i ]) #We'll append Jewels[i] in our JewelsList
34
+ for j in range (len (Stones )): #Loop through Stones
35
+ if Stones [j ] in JewelsList : #Condition-check - if Stone is in JewelsList
36
+ Number += 1 #We'll update our number counter. [Condition enter]
37
+ return Number #Finally, we'll return our counter Number.
38
+
39
+ #Example 1, Jewels = "z", Stones = "ZZ"
40
+ #JewelsList = []
41
+ #Number = 0
42
+ #i = 0;
43
+ #JewelsList = ["z"] Exit the loop as Jewels has one string character.
44
+ #j = 0;
45
+ #Condition-check Stones[0] = "Z" is not in JewelsList, we fail the condition-check
46
+ #j = 1;
47
+ #Condition-check Stones[1] = "Z" is not in JewelsList, we fail the condition-check, exit the loop.
48
+ #Return the counter Number which is Zero.
49
+ #Number = 0
0 commit comments