题解 | 杨辉三角

杨辉三角

https://www.nowcoder.com/practice/8c6984f3dc664ef0a305c24e1473729e

n=int(input())
line=[]
def tri(n):
    for i in range(n):
        a=[1]*(i+1)
        line.append(a)
        if i>=2:
            for j in range(1,i):
                line[i][j]=line[i-1][j]+line[i-1][j-1]
    return line
tri(n)
linenew=[]
for c in line:
    linenew.append(map(str,c))
for k in linenew:
    b=" ".join(k)
    print(b)

全部评论

相关推荐

02-26 09:15
已编辑
蚌埠学院 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务