Python get WR, anyone know why?


  • 0
    T
        class Solution:
    def generate(self, numRows):
        res = []
        for i in range(1, numRows+1):
            tem = [1 for i in range(i)]
            if i == 1:
                tem[0] = 1
                res.append(tem)
            else:
                pos = 0
                for j in range(1, i+1):
                    if j == 1:
                        tem[0] = 1
                    elif j == i:
                        tem[j - 1] = 1
                    else:
                        tem[j-1] = res[i-2][pos] + res[i-2][pos+1]
                        pos += 1
                res.append(tem)
        # print(res)
        return res
    

    I printed the answers is right on my computer, but get WR in the leetcode online judge...

    0->[]

    1->[[1]]

    10->[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]]


  • 0
    L
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.