package com.llh.demo; /** * 杨辉三角 * * @author llh * */ public class Test { /* * 杨辉三角 */ public static void main(String[] args) { int[] a = new int[11]; int num = 1; // for (int i = 1; i <= 10; i++) { for (int j = 1; j <= i; j++) { int c = a[j]; a[j]
在屏幕上输出一个杨辉三角,代码如下 def yanghui(): L = [1] while True: yield L L.append(0) L = [L[i - 1] + L[i] for i in range(len(L))] a = yanghui() for i in range(10) printf(next(a))
题目 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/pascals-triangle-ii 著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处. 解题 模板: /** * Note: The returned array must be malloced,
该题还是考杨辉三角计算,只不过最后每一行都放入List集合中,然后返回,直接看代码: public static List<List<Integer>> generate(int row){ List<List<Integer>> list = new ArrayList<List<Integer>>(); int[][] arr = new int[row][row]; for(int j = 0;j<row;j++) { L