119 Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
Example:
Input: 3
Output: [1,3,3,1]
Note:
Note that the row index starts from 0.
解釋下題目:
輸出楊輝三角的某一行,注意行是從0開始的
1. 跟118一樣的解法唄
實際耗時:1ms
public List<Integer> getRow(int rowIndex) {
List<Integer> list = new ArrayList<>();
list.add(0, 1);
for (int i = 0; i < rowIndex; i++) {
//第一位一定是1
list.add(0, 1);
for (int j = 1; j < list.size() - 1; j++) {
list.set(j, list.get(j) + list.get(j + 1));
}
}
return list;
}
思路是真的沒什麼好寫的......
時間複雜度O(n)
空間複雜度O(1)
相關文章
- ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)
- 119. 楊輝三角 II
- Modern Pascal is Still in the Race (Modern Pascal 仍在競賽中)
- [LeetCode] 120. TriangleLeetCode
- Windows下編譯TriangleWindows編譯
- LINUX下編譯TriangleLinux編譯
- 24點 Pascal大暴力程式
- 119 路由注意點路由
- Leetcode周賽119LeetCode
- 【博弈論】HDU - 7216 Triangle GameGAM
- 【Lintcode】359. Make Equilateral TriangleUI
- Leetcode 611 javascript Valid Triangle NumberLeetCodeJavaScript
- 119、歲暮歸南山
- Firefox 119 正式釋出Firefox
- [LeetCode] 2134. Minimum Swaps to Group All 1s Together IILeetCode
- 119 C++中的引用&C++
- CF1991F Triangle Formation 題解ORM
- 劍指 Offer 57 - II. 和為s的連續正數序列
- Mozilla Firefox 119 現已可供下載Firefox
- 976. Largest Perimeter Triangle(Leetcode每日一題-2020.11.29)LeetCode每日一題
- Range Addition II 範圍求和 II
- toMyCar:119 Uncaught ReferenceError: toJS is not defined at HTMLAnchorElement.onclickErrorJSHTML
- Hackable: II
- (原創) 如何破解Quartus II 7.2 SP1? (IC Design) (Quartus II) (Nios II)iOS
- A C++ half-edge data structure for a triangle mesh with no external dependencies whatsoeveC++Struct
- 老司機 iOS 週報 #119 | 2020-07.13iOS
- Bracket Sequences IIRacket
- Collecting Numbers II
- Reflective Journal II
- Ignatius and the Princess II
- 2.12 それは命の證 ——ARC119~121
- PostgreSQL DBA(119) - pgAdmin(LIMIT:Index Scan vs Bitmap Index Scan)SQLMITIndex
- 劍指 Offer 14- II. 剪繩子 II
- 設計模式II設計模式
- Spiral-matrix-ii
- 機器學習筆記 - Pascal VOC資料集使用FCN語義分割機器學習筆記
- 119的節日的安排,我們應該做些什麼
- SuperData:預計2020年全球VR遊戲收入增長119%VR遊戲