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列【从0开始
2.解题思路:
见代码
3.代码
[title] [] [url] [link text]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
publicclass{ public List<Integer> getRow(int rowIndex){ List<Integer> ans = new ArrayList<Integer>(); ans.add(1); for (int i = 1; i <= rowIndex; i++) { for (int j = i - 1; j > 0; j--) {
近期评论