You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def transTriple(triple):
m, n = shape(triple)
transMatrix = []
# sortedIndex = array([m[1] for m in triple]).argsort()
for i in range(m):
# tempArray = triple[sortedIndex[i]]
tempArray = triple[i]
transMatrix.append([tempArray[1], tempArray[0], tempArray[2]])
return transMatrix
Activity
zhu733756 commentedon Apr 22, 2020
丑数哪一题 没必要加循环,可以简单判断最小的丑数包含几个2,3,5
def solution(index: int) -> int:
'''
1 -> 1
2 -> 2 12
3 -> 3 13
4 -> 4 22
5 -> 5 15
6 -> 6 23
7 -> 8 222
8 -> 9 33
9 -> 10 25
10 -> 12 223
11 -> 15 35
直接判断这个数里面分别包含几个2,3,5
'''
if index < 0:
return
ants = [1] * index
index2, index3, index5 = 0, 0, 0
for i in range(1,index):
ants[i] = min(ants[index2] * 2, ants[index3] * 3, ants[index5] * 5)
if ants[index2] * 2 == ants[i]:
index2 += 1
if ants[index3] * 3 == ants[i]:
index3 += 1
if ants[index5] * 5 == ants[i]:
index5 += 1
return ants[-1]
print(solution(11))
[-]targetofferbyPython 稀疏矩阵转置没必要用排序,只需要交换三元组的行列角标即可[/-][+]targetofferbyPython 稀疏矩阵转置、丑数优化[/+]