zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1314. 矩阵区域和 | Matrix Block Sum

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址: https://www.cnblogs.com/strengthen/p/12185567.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    Given a m * n matrix mat and an integer K, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K <= r <= i + K, j - K <= c <= j + K, and (r, c) is a valid position in the matrix.
     

    Example 1:

    Input: mat = [[1,2,3],[4,5,6],[7,8,9]], K = 1
    Output: [[12,21,16],[27,45,33],[24,39,28]]
    Example 2:

    Input: mat = [[1,2,3],[4,5,6],[7,8,9]], K = 2
    Output: [[45,45,45],[45,45,45],[45,45,45]]
     

    Constraints:

    m == mat.length
    n == mat[i].length
    1 <= m, n, K <= 100
    1 <= mat[i][j] <= 100


    给你一个 m * n 的矩阵 mat 和一个整数 K ,请你返回一个矩阵 answer ,其中每个 answer[i][j] 是所有满足下述条件的元素 mat[r][c] 的和: 

    i - K <= r <= i + K, j - K <= c <= j + K 
    (r, c) 在矩阵内。
     

    示例 1:

    输入:mat = [[1,2,3],[4,5,6],[7,8,9]], K = 1
    输出:[[12,21,16],[27,45,33],[24,39,28]]
    示例 2:

    输入:mat = [[1,2,3],[4,5,6],[7,8,9]], K = 2
    输出:[[45,45,45],[45,45,45],[45,45,45]]
     

    提示:

    m == mat.length
    n == mat[i].length
    1 <= m, n, K <= 100
    1 <= mat[i][j] <= 100

  • 相关阅读:
    数据库中索引的概念
    将博客搬至CSDN
    数据结构之图(图的基本操作)
    数据结构之图(图的简介)
    数据结构树之红黑树
    图解数据结构树之AVL树
    排序算法之选择排序
    数据结构树之二分查找树
    Kali-Dos洪水攻击之Hping3
    Linux系统查看CPU使用率命令
  • 原文地址:https://www.cnblogs.com/strengthen/p/12185567.html
Copyright © 2011-2022 走看看