Last active
February 24, 2018 23:49
-
-
Save dilanshah/8dacad4a8204221808398835b0324e30 to your computer and use it in GitHub Desktop.
Problem 771. Jewels and Stones on Leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Strings J = types of stones that are jewels | |
# String S = stones you have | |
# Input | |
# J = "aA", S = "aAAbbbb" | |
# Output | |
# 3 | |
# create a dictionary where the key is the char and the value is the number of occurrences | |
def jewels(S, J): | |
jewels = {x: 0 for x in J} | |
for char in S: | |
if char in jewels.keys(): | |
jewels[char] += 1 | |
return sum(jewels.values()) | |
J = "aZAb" | |
S = "aAAizbbbbc" | |
jewels(S,J) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment