LeetCode(力扣):杨辉三角||

java 复制代码
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> currentRow = new ArrayList<>();
        currentRow.add(1);
        //依次替换上一行
        for(int i = 1;i <= rowIndex;i++){
            //先在结尾放1
            currentRow.add(1);
            //设置中间数字的值
            for(int j = i - 1;j > 0;j--){
                currentRow.set(j,currentRow.get(j) + currentRow.get(j - 1));
            }
        }
        return currentRow;
    }
}

中间数字=自己+左边数字,只能从后往前算,如果从前往后算,前面数字先计算完成后,后面数字再计算这时他的左邻居相当于是变了数字的。

相关推荐
铮铭14 分钟前
【论文阅读】世界模型发展脉络整理---Understanding World or Predicting Future? A Comprehensive Survey of World Models
论文阅读·人工智能·算法·机器人
灵智实验室28 分钟前
PX4状态估计技术EKF2详解(四):EKF2 Output Predictor——从延迟估计到实时输出
算法·无人机·px 4
科研小白_1 小时前
【MATLAB点云处理基础】基于区域生长算法的桥墩面域点云分割
算法
paeamecium1 小时前
【PAT甲级真题】- Shuffling Machine (20)
c++·算法·pat考试·pat
m0_737539371 小时前
pod Scheduler调度
算法·贪心算法
此生决int1 小时前
算法从入门到精通——双指针
算法
普马萨特1 小时前
Uber H3:地理网格索引在空间数据分析中的应用
数据结构·算法
alphaTao1 小时前
LeetCode 每日一题 2026/5/11-2026/5/17
算法·leetcode
洛水水1 小时前
【力扣100题】45.零钱兑换
算法·leetcode·职场和发展
Aaron15882 小时前
全频段 SDR干扰源模块解决方案(星链干扰、LORA无人机干扰)
人工智能·算法·fpga开发·硬件架构·硬件工程·无人机·信息与通信