zoukankan      html  css  js  c++  java
  • leetcode------Pascal's Triangle

    标题: Pascal's Triangle
    通过率: 30.7%
    难度: 简单

    Given numRows, generate the first numRows of Pascal's triangle.

    For example, given numRows = 5,
    Return

    [
         [1],
        [1,1],
       [1,2,1],
      [1,3,3,1],
     [1,4,6,4,1]
    ]

    中国人一般都叫这个杨辉三角,国外人叫pascal,这个题道理都是明白的。。就是实现起来的问题了。。道理比较简单,一动手全部瞎,这种题超级适合出笔试题,即简单,实用,还不能被鄙视着吐槽说笔试太难,具体细节看代码就行了:
     1 public class Solution {
     2     public List<List<Integer>> generate(int numRows) {
     3         List<List<Integer>> result=new ArrayList<List<Integer>>();
     4         for(int i=0;i<numRows;i++){
     5             List<Integer> tmp=new ArrayList<Integer>();
     6             tmp.add(1);
     7             if(i>0){
     8                 for(int j=0;j<result.get(i-1).size()-1;j++)
     9                     tmp.add(result.get(i-1).get(j)+result.get(i-1).get(j+1));
    10                     tmp.add(1);
    11             }
    12             result.add(tmp);
    13         }
    14         return result;
    15     }
    16 }
  • 相关阅读:
    adb使用项目导入等
    ThreadLocal类理解
    Spring MVC MyBatis
    Spring MVC原理图
    Spring MVC返回JSON的几种方法
    Understanding REST
    链表
    存储构造题(Print Check)
    线状DP(石子归并)
    线段树(与区间有关的操作)
  • 原文地址:https://www.cnblogs.com/pkuYang/p/4223238.html
Copyright © 2011-2022 走看看