Commit e2a30cf9 by 牛家玺

Initial commit

parents
def numJewelsInStones(J, S):
stores = {}
for c in S:
if c in stores:
stores[c] = stores[c] + 1
else:
stores[c] = 1
count = 0
for c in J:
if c in stores:
count += stores[c]
print(count)
J = "aA"
S = "aAAbbbb"
numJewelsInStones(J, S)
J = "z"
S = "ZZ"
numJewelsInStones(J, S)
def peakIndexInMountainArray(mountain):
height = len(mountain)
low = 0
while low <= height:
mid = (height + low) // 2
if array[mid] > array[mid - 1] and array[mid] > array[mid + 1]:
print(mid)
break
elif array[mid] > array[mid + 1]:
height = mid - 1
else:
low = mid + 1
array = [0, 1, 0]
peakIndexInMountainArray(array)
array = [0, 2, 1, 0]
peakIndexInMountainArray(array)
array = [0, 1, 2, 3, 7, 6, 5, 4, 2, 1, 0]
peakIndexInMountainArray(array)
array = [0, 1, 2, 7, 6, 5, 4, 0]
peakIndexInMountainArray(array)
morse = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
morse_dict = {chr(i + 97): morse[i] for i in range(0, len(morse))}
def uniqueMorseRepresentations(words):
unique = set()
for word in words:
unique.add(toMorseCode(word))
return len(unique)
def toMorseCode(word):
morse_code = ""
for char in word:
morse_code += morse_dict.get(char)
return morse_code
check_words = ["gin", "zen", "gig", "msg"]
print(uniqueMorseRepresentations(check_words))
def convert(s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment