在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbours of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighboors if they share one edge. Return the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot. Binary matrix is a matrix with all cells equal to 0 or 1 only. Zero matrix is a matrix with all cells equal to 0.
Example 1:
Input: mat = [[0]] Input: mat = [[1,1,1],[1,0,1],[0,0,0]] Input: mat = [[1,0,0],[1,0,0]] Constraints: m == mat.length 给你一个 m x n 的二进制矩阵 mat。 每一步,你可以选择一个单元格并将它反转(反转表示 0 变 1 ,1 变 0 )。如果存在和它相邻的单元格,那么这些相邻的单元格也会被反转。(注:相邻的两个单元格共享同一条边。) 请你返回将矩阵 mat 转化为全零矩阵的最少反转次数,如果无法转化为全零矩阵,请返回 -1 。 二进制矩阵的每一个格子要么是 0 要么是 1 。 全零矩阵是所有格子都为 0 的矩阵。
示例 1:
输入:mat = [[0,0],[0,1]] 输入:mat = [[0]] 输入:mat = [[1,1,1],[1,0,1],[0,0,0]] 输入:mat = [[1,0,0],[1,0,0]] 提示: m == mat.length |
请发表评论