问题:求矩阵任意子矩阵的元素和 思路 创建前缀和矩阵 pre[i][j] 表示原矩阵 [0,0] 到 [i,j] 的子矩阵的元素和; 那么前缀和公式为:pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + matrix[i][j]; 子矩阵 [i1,j1] 到 [i,j] 的元素和公式为:ans = pre[i][j] - pre[i][j1] - pre[i1][j] + pre[i1][j1] function matrixSum(matrix){ const m = matrix.length; const n = matrix[0].length; } 参考文章 https://leetcode.cn/problems/image-smoother/solutions/2992275/tu-jie-er-wei-qian-zhui-he-tui-dao-ji-su-1est/?envType=daily-question&envId=2024-11-18