题目描述:

自己的提交:

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-重构二进制矩阵的更多相关文章

  1. LeetCode 1253. 重构 2 行二进制矩阵 - Java - 统计

    题目链接:https://leetcode-cn.com/contest/weekly-contest-162/problems/reconstruct-a-2-row-binary-matrix/ ...

  2. LeetCode 1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (最少翻转次数将二进制矩阵全部置为0)

    给一个矩阵mat,每个格子都是0或1,翻转一个格子会将该格子以及相邻的格子(有共同边)全部翻转(0变为1,1变为0) 求问最少需要翻转几次将所有格子全部置为0. 这题的重点是数据范围,比赛结束看了眼数 ...

  3. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  4. C#LeetCode刷题之#566-重塑矩阵( Reshape the Matrix)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3720 访问. 在MATLAB中,有一个非常有用的函数 resha ...

  5. [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 ...

  6. 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 ...

  7. 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 ...

  8. [LeetCode] Count Binary Substrings 统计二进制子字符串

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  9. LeetCode 67. Add Binary (二进制相加)

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

随机推荐

  1. 使用ubuntu的一些操作笔记20191203

    前言 环境: virtualbox + Ubuntu 16.04 情况: 可以进入虚拟机中Ubuntu系统的桌面,但是外部可以访问到 ssh,输入正确的用户名和密码无法登录 无法正常启动 Apache ...

  2. 3、selenium 问题汇总

    一.'chromedriver' executable needs to be in PAT: 解决方法  下载谷歌驱动文件:Chromedriver.exe 将Chromedriver.exe 拷贝 ...

  3. 1.初步了解IOC容器

    学习地址:腾讯课堂   https://ke.qq.com/course/28986?_bid=167&_wv=3&from=iosapp 1.什么是IOC容器 定义: 1.是一个可以 ...

  4. cocos2D-X call JNIHelper

    #ifndef _WIN32 JNIEnv *j = JniHelper::getEnv(); if (j == nullptr || j == NULL) {test += "JNIEnv ...

  5. 每天一个linux命令:nl(12)

    nl nl命令读取 file 参数(缺省情况下标准输入),计算输入中的行号,将计算过的行号写入标准输出.在输出中,nl命令根据您在命令行中指定的标志来计算左边的行.输入文本必须写在逻辑页中.每个逻辑页 ...

  6. Yii2邮件发送

    1.在配置文件main-local.php components=>[]里面配置 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ...

  7. UNP学习 非阻塞I/O

    缺省状态下,套接口时阻塞方式的.这意味着当一个套接口调用不能立即完成时,进程进入睡眠状态,等待操作完成.我们将可能阻塞的套接口调用分成四种. 1.输入操作:read.readv.recv.recvfr ...

  8. layer icon对应图标

    layer icon对应图标 信息框(msg.alert.open.confirm) icon:0 icon:1 icon:2 icon:3 icon:4 icon:5 icon:6 icon:16 ...

  9. 为何使用Html5+CSS3

    一:大多浏览器支持,低版本也没问题 我看点这方面的资料,是为了做手机应用网站(有三个方案,这个是备用方案),可以开发响应式网站,可以脱离开发平台进行跨平台. 在Html5网页中引入Modernizr, ...

  10. es6 常用的语法

    1.es6 模块化 你import 和 export export default 为默认到处,而export能导出多个方法或变量. 2. es6——class与普通构造函数的区别 class的继承方 ...