【Leecode刷题】字典使用&杨辉三角
本题的重点是:
map_ = {}
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
asc = 97
for i in range(26):
map_[chr(asc+i)] = morse[i]
# set把列表转换成集合
map_morse = set(map_morse)
class Solution(object):
def uniqueMorseRepresentations(self, words):
"""
:type words: List[str]
:rtype: int
"""
map_ = {}
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
asc = 97
for i in range(26):
map_[chr(asc+i)] = morse[i]
map_morse = []
for word in words:
temp = ""
for alpha in word:
temp += map_[alpha]
map_morse.append(temp)
map_morse = set(map_morse)
return len(map_morse)
杨辉三角第 n n n行第 i i i个数据 ( 1 ≤ i ≤ n ) (1 \leq i \leq n) (1≤i≤n)数据是 C n i C_n^i Cni
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
def mutiple(m):
num=1
for i in range(m):
num=num*(i+1)
return num
def zuheshu(m,n):
return mutiple(m)/(mutiple(n)*mutiple(m-n))
a=[]
for i in range(rowIndex+1):
a.append(zuheshu(rowIndex,i))
return a