letcode 118
来源:互联网 发布:工作督促软件 编辑:程序博客网 时间:2024/04/30 11:11
问题描述:
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]]
import java.util.*;class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> list=new ArrayList<List<Integer>>(); for(int i=0;i<=numRows-1;i++){long num=1;ArrayList<Integer> al=new ArrayList<Integer>();for(int j=0;j<=i;j++){al.add((int)num);num=num*(i-j)/(j+1);}list.add(al);}return list; }}class Test118 {public static void main(String[] args) {Solution s=new Solution();System.out.println(s.generate(5));}}
0 0
- letcode 118
- LETCODE 165
- letcode-TwoSum
- LetCode 412
- LetCode 371
- LetCode:Palindrome Partitioning II
- letcode Gray code
- [letcode 134] Gas Station
- letcode - Dungeon Game
- [letcode]Perfect Squares
- letcode remove-element
- Letcode 1.Two Sum
- Generate Parentheses--letcode
- Letcode 198 House Robber
- Letcode刷题心得
- letcode 9 Palindrome Number
- letcode 答案(Python)
- 【面试准备】letcode—LRU
- MYSQL中INET_ATON(expr)函数的调查
- 欧拉函数模版
- VS2013与MySql建立连接;您的项目引用了最新实体框架;
- 安卓汉字转拼音字符串,进行模糊搜索时使用
- 国内计算机期刊
- letcode 118
- 在Windows下搭建React Native Android开发环境
- C语言的数据类型转换
- stdint--ISO C99: 7.18 Integer typesC语言扩展类型
- 前端一些网站
- Mac 搭建本地Apache服务器
- 由二叉树的遍历序列恢复二叉树
- 视频去除水印、台标和logo,并重新在生成新的视频
- hdu2602(01背包)