LeetCode119.杨辉三角II
生活随笔
收集整理的這篇文章主要介紹了
LeetCode119.杨辉三角II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定一個非負索引?k,其中?k?≤?33,返回楊輝三角的第?k?行。
在楊輝三角中,每個數是它左上方和右上方的數的和。
示例:
輸入: 3 輸出: [1,3,3,1]進階:
你可以優化你的算法到?O(k) 空間復雜度嗎?
class Solution {public List<Integer> getRow(int rowIndex) {List<Integer> res = new ArrayList<Integer>();for (int i = 0;i<=rowIndex;i++) {res.add(1);for (int j=i-1;j>=1;j--) {res.set(j, res.get(j)+res.get(j-1));}}return res;} }?
轉載于:https://www.cnblogs.com/airycode/p/9777034.html
總結
以上是生活随笔為你收集整理的LeetCode119.杨辉三角II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python3 写JSON数据到文件(多
- 下一篇: 二十八种未授权访问漏洞合集(暂时最全)