楊輝三角

class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        result = []
        if numRows == 0:
            return []
        i = 0
        j = 0
        while(i < numRows):
            temp_result = []
            while(j < i + 1):
                if j == 0 or j == i:
                    temp_result.append(1)
                else:
                    temp_result.append(result[i-1][j-1] + result[i-1][j])#找規律就行
                j += 1
            result.append(temp_result)
            i += 1
            j = 0
        return result

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章