Skip to content

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

Open

Description

@zhu733756

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

  1. zhu733756 commented on Apr 22, 2020

    @zhu733756
    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))

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions