Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

targetofferbyPython 稀疏矩阵转置、丑数优化 #23

Open
zhu733756 opened this issue Apr 21, 2020 · 1 comment
Open

targetofferbyPython 稀疏矩阵转置、丑数优化 #23

zhu733756 opened this issue Apr 21, 2020 · 1 comment

Comments

@zhu733756
Copy link

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

@zhu733756
Copy link
Author

丑数哪一题 没必要加循环,可以简单判断最小的丑数包含几个2,3,5
def solution(index: int) -> int:
'''
1 -> 1
2 -> 2 12
3 -> 3 1
3
4 -> 4 22
5 -> 5 1
5
6 -> 6 23
7 -> 8 2
22
8 -> 9 3
3
9 -> 10 25
10 -> 12 2
23
11 -> 15 3
5
直接判断这个数里面分别包含几个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))

@zhu733756 zhu733756 changed the title targetofferbyPython 稀疏矩阵转置没必要用排序,只需要交换三元组的行列角标即可 targetofferbyPython 稀疏矩阵转置、丑数优化 Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant