119. Pascal's Triangle II
来源:互联网 发布:tcp协议端口号 编辑:程序博客网 时间:2024/05/17 02:58
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1]
.
Note:
Could you optimize your algorithm to use only O(k) extra space?
数学方法,第K行的所有元素有K+1个,分别是
Ck0,Ck1,Ck2…………,Ckk-1,Ckk 就是算组合数。
public class Solution { public List<Integer> getRow(int rowIndex){List<Integer>retlist=new ArrayList<>();for(int i=0;i<=rowIndex;i++)retlist.add((int) com(rowIndex, i));return retlist;}private long com(int n, int r){if (n - r < r)r = n - r; long i, j, s = 1;for (i = 0, j = 1; i < r; ++i){s *= (n - i);for (; j <= r && s % j == 0; ++j)s /= j;}return s;}}
0 0
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 119. Pascal's Triangle II
- 多态的理解
- [libevent]epoll_dispatch()
- 日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个嫌疑犯的一个。以下为4个嫌疑犯的供词
- Linux Makefile文件编写详细步骤与实践
- xampp中修改mysql默认空密码(root密码)的方法分享
- 119. Pascal's Triangle II
- <meta http-equiv="X-UA-Compatible" content="IE=edge">的说明
- app里面打开safari浏览器带入部分信息
- VS2015使用Sublime Text 主题
- The Python Tutorial学习笔记(2)--map、reduce、filter介绍
- UIWebView 后台播放音乐
- XEN - Installing and Configuring Fedora Xen Virtualization
- 能够提高开发效率的Eclipse实用操作
- react native手动 npm init