Skip to content

Instantly share code, notes, and snippets.

@dilanshah
Last active February 24, 2018 23:49
Show Gist options
  • Save dilanshah/8dacad4a8204221808398835b0324e30 to your computer and use it in GitHub Desktop.
Save dilanshah/8dacad4a8204221808398835b0324e30 to your computer and use it in GitHub Desktop.
Problem 771. Jewels and Stones on Leetcode
# 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