zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1277. 统计全为 1 的正方形子矩阵 | Count Square Submatrices with All Ones

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

    Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.

    Example 1:

    Input: matrix =
    [
      [0,1,1,1],
      [1,1,1,1],
      [0,1,1,1]
    ]
    Output: 15
    Explanation:
    There are 10 squares of side 1.
    There are 4 squares of side 2.
    There is 1 square of side 3.
    Total number of squares = 10 + 4 + 1 = 15.
    Example 2:

    Input: matrix =
    [
    [1,0,1],
    [1,1,0],
    [1,1,0]
    ]
    Output: 7
    Explanation:
    There are 6 squares of side 1.
    There is 1 square of side 2.
    Total number of squares = 6 + 1 = 7.
     

    Constraints:

    1 <= arr.length <= 300
    1 <= arr[0].length <= 300
    0 <= arr[i][j] <= 1


    给你一个 m * n 的矩阵,矩阵中的元素不是 0 就是 1,请你统计并返回其中完全由 1 组成的 正方形 子矩阵的个数。

    示例 1:

    输入:matrix =
    [
      [0,1,1,1],
      [1,1,1,1],
      [0,1,1,1]
    ]
    输出:15
    解释:
    边长为 1 的正方形有 10 个。
    边长为 2 的正方形有 4 个。
    边长为 3 的正方形有 1 个。
    正方形的总数 = 10 + 4 + 1 = 15.
    示例 2:

    输入:matrix =
    [
    [1,0,1],
    [1,1,0],
    [1,1,0]
    ]
    输出:7
    解释:
    边长为 1 的正方形有 6 个。
    边长为 2 的正方形有 1 个。
    正方形的总数 = 6 + 1 = 7.
     

    提示:

    1 <= arr.length <= 300
    1 <= arr[0].length <= 300
    0 <= arr[i][j] <= 1

  • 相关阅读:
    文件操作一写操作
    文件操作一读操作
    python基础初识
    while循环和格式化输出
    python基础数据类型一(整数类型和布尔值)
    CentOS 6下安装nodejs 0.9.0(转)
    CentOS安装Python教程
    Discuz! X2.5数据库字典(转)
    SQL 语句中的union操作符
    thinkphp空操作和配置文件实现简化路由
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151547.html
Copyright © 2011-2022 走看看