zoukankan      html  css  js  c++  java
  • 119.杨辉三角II

    这道题和第118题是一样的,需要注意这道题目对行数的要求

            # 定义一个列表,用来存放数据
            num_list = []
            for index1 in range(rowIndex + 1):
                # 每一行要先添加一个空列表
                num_list.append([])
                # 注意这里的for循环的范围
                for index2 in range(index1 + 1):
                    # 将值为一的位置规定好
                    if index1 == 0  or index2 == 0 or index2 == index1 :
                        num_list[index1].append(1)
                    # 按照题目要求计算就好了
                    else:
                        num_list[index1].append(num_list[index1 - 1][index2 - 1] + num_list[index1 - 1][index2])
            return num_list[rowIndex]
  • 相关阅读:
    lambda表达式
    切片操作
    小样本学习(Few-shot Learning)
    TensorFlow Eager 模式
    tensorflow读入数据集的方式
    综述类解读
    pyCharm永久激活
    shell脚本教程
    GNN
    Tomcat配置优化
  • 原文地址:https://www.cnblogs.com/cong12586/p/13214429.html
Copyright © 2011-2022 走看看