leetcode-162周赛-1253-重构二进制矩阵
题目描述:


自己的提交:
class Solution:
def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:
res = [[],[]]
for v,i in enumerate(colsum):
if i > 2: return []
elif i == 2:
res[0].append(1)
res[1].append(1)
upper,lower = upper-1,lower-1
elif i == 1:
if upper > lower:
res[0].append(1)
res[1].append(0)
upper -= 1
else:
res[1].append(1)
res[0].append(0)
lower -= 1
else:
res[0].append(0)
res[1].append(0)
if upper < 0 or lower < 0:
return []
if v == len(colsum)-1 and upper|lower:
return []
return res
leetcode-162周赛-1253-重构二进制矩阵的更多相关文章
- LeetCode 1253. 重构 2 行二进制矩阵 - Java - 统计
题目链接:https://leetcode-cn.com/contest/weekly-contest-162/problems/reconstruct-a-2-row-binary-matrix/ ...
- LeetCode 1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (最少翻转次数将二进制矩阵全部置为0)
给一个矩阵mat,每个格子都是0或1,翻转一个格子会将该格子以及相邻的格子(有共同边)全部翻转(0变为1,1变为0) 求问最少需要翻转几次将所有格子全部置为0. 这题的重点是数据范围,比赛结束看了眼数 ...
- # Leetcode 67:Add Binary(二进制求和)
Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...
- C#LeetCode刷题之#566-重塑矩阵( Reshape the Matrix)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3720 访问. 在MATLAB中,有一个非常有用的函数 resha ...
- [LeetCode] Score After Flipping Matrix 翻转矩阵后的分数
We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...
- LeetCode 73. Set Matrix Zeros(矩阵赋零)
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...
- LeetCode 54. Spiral Matrix(螺旋矩阵)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- [LeetCode] Count Binary Substrings 统计二进制子字符串
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- LeetCode 67. Add Binary (二进制相加)
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
随机推荐
- solaris系统动态查看swap的使用情况
root@tt # root@tt # prstat -aPlease wait... PID USERNAME SIZE RSS STATE PRI NICE TIME CPU ...
- Bootstrap 过渡效果
<!DOCTYPE html> <html <!DOCTYPE html> <html lang="en"> <head> & ...
- 微信小程序学习一 微信小程序的四个基本文件
微信小程序有四种类型的文件 js 类型文件 小程序的逻辑代码文件 小程序对js es6的处理比较友好,基本上我们的es6语法都需要使用babel插件去转化成es5(具体是什么原因,自己可以去了解一下) ...
- hadoop HA集群的安装
1.hadoop集群规化 ip 主机名 安装软件 角色 运行进程 10.124.147.22 hadoop1 jdk.zookeeper.hadoop namenode/zookeeper/jobhi ...
- OpenCV常用基本处理函数(1)读写
图像的基本操作 cv.imread() 读取图片 cv.imshow() 显示图片 cv2.imwrite() 保存图像 使用摄像头捕获实时图像 OpenCV 为这中应用提供了 ...
- C#中using语句是什么意思
使用using语句最终生成的其实是一个try, finally代码块,在finally代码块里释放资源.要求是:为 using 语句提供的对象必须实现 IDisposable 接口.此接口提供了 Di ...
- 【leetcode】1005. Maximize Sum Of Array After K Negations
题目如下: Given an array A of integers, we must modify the array in the following way: we choose an i an ...
- Eu
<parent> <artifactId>microservice-cloud-01</artifactId> <groupId>com.mengx ...
- python dir()详解
Python dir() 函数 Python 内置函数 描述 dir() 函数不带参数时,返回当前范围内的变量.方法和定义的类型列表:带参数时,返回参数的属性.方法列表.如果参数包含方法__dir__ ...
- mysql完美增量备份脚本
是否因为mysql太大,来回备份浪费资源带宽而发愁,如果想解决这个麻烦就需要增量备份. vi /etc/my.cnf开启日志及定期清理日志log-bin=mysql-binbinlog_format= ...