【leetcode】73.(Medium)Set Matrix Zeroes

模糊综合评价模型 一.引子 1.数学归纳法:同高中知识 2.秃子悖论:秃子悖论 这俩个例子都是类似于“量变引起质变”的道理,而在数学中我们把这类问题的性质叫做“模糊性”,在生活中我们也经常能遇到一些模糊的概念,比如年轻、帅、很少很多… 二.概述 模糊综合评价法是一种基于模糊数学的综合评价方法。该综合评价法根据模糊数学的隶属度理论把定性评价转化为定量评价,即用模糊数学对受到多种因素制约的事物或对象做出一个总体的评价。它具有结果清晰,系统性强的特点,能较好地解决模糊的、难以量化的问题,适合各种非确定性问题的解决。——来自百度百 阅读详情

解题思路:
首先空间复杂度为O(m*n)的做法是,直接copy一套matrix来记录
空间复杂度为O(m+n)的做法是设置数组row[m]和column[n]来记录每行每列的0的情况
空间复杂度为O(1)的情况就是设置两个boolean变量,首先判定第一行和第一列是否会最终变为0,然后从第一行第一列(最左上角位置为第0行第0列)开始,更新matrix。最后再根据这两个boolean变量来更新matrix的第一行和第一列。

提交代码:

class Solution {
    public void setZeroes(int[][] matrix) {
    	boolean zeroColumn=false,zeroRow=false;
    	
    	for(int i=0;i<matrix.length;i++)
        	if(matrix[i][0]==0) {
        		zeroColumn=true;
        		break;
        	}
    	
    	for(int j=0;j<matrix[0].length;j++)
    		if(matrix[0][j]==0) {
        		zeroRow=true;
        		break;
        	}
    	
    	for(int i=0;i<matrix.length;i++)
    		for(int j=0;j<matrix[0].length;j++)
    			if(matrix[i][j]==0) {
    				matrix[i][0]=0;
    				matrix[0][j]=0;
    			}
    			
    	for(int i=1;i<matrix.length;i++)
    		for(int j=1;j<matrix[0].length;j++)
    			if(matrix[i][0]==0||matrix[0][j]==0)
    				matrix[i][j]=0;
    	
    	if(zeroColumn)
    		for(int i=0;i<matrix.length;i++)
    			matrix[i][0]=0;
    	if(zeroRow)
    		for(int j=0;j<matrix[0].length;j++)
    			matrix[0][j]=0;
    }
}

运行结果:
在这里插入图片描述

离线迁移 Conda 环境到 Windows 服务器:用 conda-pack 摆脱硬路径限制 在进行深度学习算法的环境部署时,由于生产服务器被彻底隔离外网,只能把conda中env文件夹中的虚拟环境文件夹从开发机直接拷到Windows 服务器,但在运行labelimg等工具时可能报错,因此用conda-pack来解决。 阅读详情

相关推荐

团队管理中最棘手的6个问题

研发团队的管理棘手问题,大多集中在。

xiaolyuh的专栏 743

[Leetcode 73, medium] Set Matrix Zeroes

Problem: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solu

算法的实践 546

最新,弱小目标检测数据集,持续更新中。

梳理了最新的下弱小目标检测数据库,方便后续开发使用

weixin_43331421的博客 4095

Leetcode OJ 73 Set Matrix Zeroes [Medium]

题目描述: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 解答: public class Solution { public void setZeroes(int[][] matrix) { boolean fr = false,fc = f

大吱的博客 352

开源低场MRI系统构建:从原理到三天实现

磁共振成像(MRI)作为现代医学影像的核心技术,其高场强系统存在成本和技术门槛问题。低场MRI通过开源硬件和模块化设计实现技术民主化,采用永磁体替代超导磁体可大幅降低系统复杂度。本文以H型永磁体设计为例,结合MaRCoS开源控制库和PyPulseq脉冲序列工具,展示了如何快速构建教育级MRI系统。关键技术包括遗传算法优化的匀场方案、CNC加工的梯度线圈,以及基于Red Pitaya的SDR控制架构。这种轻量化方案特别适合医学物理教学和脉冲序列开发验证,为MRI技术在资源有限地区的普及提供了新思路。

weixin_30470643的博客 449

PCIe学习笔记(一)-------1.3 PCIe数据包(TLP,DLLP,PLP)

1,PCIe的层次结构 PICe设备在硬件电路上可以分为三个层次结构:事务层(Transaction Layer)、数据链路层(Data Link Layer)、物理层(Physical)。每一个层次又可以分为两个部分,分别为处理发送和处理接收的部分。 也可以分为四个层次,将事务层以上的层次称为软件层(Software Layer)。 2,PCIe数据包 前面已经说过PCIe之间是以数据包的形式来传输数据的,协议共定义了3类数据包。与处理层相关的是处理层数据包(TLP),与数据链路层相关的是数据

llxxyy507的博客 2万+

【Leetcode】73. Set Matrix Zeroes[Medium]

Description Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Follow up: A straight forward solution using O(mn) space is probably a bad idea. A simple imp...

Joyer的博客 145

芒果YOLO11改进21:检测头Head篇:即插即用|新颖轻量化非对称多级压缩LADH检测头,原创改进适配YOLOv8高效检测头,检测头新颖性改进,全网首发独一份

检测头Head篇:即插即用|新颖轻量化非对称多级压缩LADH检测头,原创改进适配YOLOv8高效检测头,检测头新颖性改进,全网首发独一份

包括YOLOv5、YOLOv7、YOLOv8等模型改进 792

Leetcode 73. Set Matrix Zeroes [medium][java]

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example Solution 1: brute force Consideration Use a boolean matrix to mark if the element has been set t...

inkhk的博客 339

FPGA原型验证(八):SoC设计适配与实现策略

时钟门控在SoC设计中很常见,应该小心处理门控时钟,以成功地在FPGA上原型化SoC设计。现代FPGA综合工具在正确约束的情况下,可以自动处理大多数门控时钟。通过遵循本章中的指导方针,即使具有复杂时钟门控的SoC设计也可以得到处理,并成功地在FPGA上进行原型化。

叫好与叫座虽然不是对立面,但想在同一个作品中达到双重效果很难。 477

扩展卡尔曼滤波 (EKF, Extended Kalman Filter) 算法详解及案例分析

扩展卡尔曼滤波是一种用于估计非线性动态系统状态的递归算法。其目标是通过结合非线性系统模型和观测数据,估计系统的最优状态。

闲人编程的博客 2385

【LeetCode】 73. Set Matrix Zeroes 矩阵置零(Medium)(JAVA)

【LeetCode】 73. Set Matrix Zeroes 矩阵置零(Medium)(JAVA) 题目地址: https://leetcode.com/problems/set-matrix-zeroes/ 题目描述: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-...

qq_16927853的博客 199

结构光之相移法+多频外差的数学原理推导

‍论文:基于数字光栅投影的结构光三维测量技术与系统研究 [博]作者:李中伟 华中科技大学 2007功能:相移法:多频外差(三频N步相移法)01 相移法图1 待写入投影仪的理想N步相移条纹通常对于 步相移来说,生成第 幅条纹图像(如图1所示)的公式如下:402 Payment Required其中::背景光强:调制强度:像素点横向坐标:相移值图2 相机拍摄到的实际 N ......

3D视觉工坊 1189

Leetcode 73. Set Matrix Zeroes (Medium) (cpp)

Leetcode 73. Set Matrix Zeroes (Medium) (cpp)

还是需要多学习!闷声大发财,这是坠吼的! 1124

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LeetCode 73. Set Matrix Zeroes(Medium)

原文出处,请点击彼得攀的小站 查阅更多的题解,请点击 Problem 73. Set Matrix Zeroes(Medium) Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Input: [ [1,1,1], [1,...

彼得.攀的blog 176

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

leetcode 73. Set Matrix Zeroes (medium)

为了使用常数空间大小,将矩阵的第一行、第一列用来记录是否当前行、列需要全部置为0 class Solution { public: void setZeroes(vector<vector<int>> &matrix) { size_t m = matrix.size(); size_t n = matrix[0].size(); bool ro...

Rh's blog 217

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Leetcode: 73. Set Matrix Zeroes(Week15, Medium)

Leetcode 73 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.题意:将矩阵中元素为0的对应行、列全部置0. 思路:遍历整个矩阵,用两个set容器存储0元素的行与列,然后扫描完后,再执行置0操作。其中,对置换行,可以赋值长为n且全为0的vector数

linwh8的博客 454

LeetCode Top Interview Questions 73. Set Matrix Zeroes (Java版; Medium)

welcome to my blog LeetCode Top Interview Questions 73. Set Matrix Zeroes (Java版; Medium) 题目描述 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1:...

littlehaes的博客 183

LeetCode-73-Set Matrix Zeroes(数组)-Medium

题意理解: 如果矩阵中某个点的值为0,则该点所在的行和列上所有的数均设置为0; 题目分析: 为了降低空间复杂度,需要在当前数组进行设置为0的操作:使用一个list记录所有值为0的位置,然后再对先前的数组进行对应行列设置为0的操作; 解题代码: public class Solution { private class Pair{ publi

eddy_liu的专栏 960

【LeetCode】(73)Set Matrix Zeroes(Medium)

题目 Set Matrix Zeroes  Total Accepted: 43426 Total Submissions: 137908My Submissions Question  Solution  Given a m x n matrix, if an element is 0, set its entire row and column

Row Row Row your boat 311

LeetCode 73. Set Matrix Zeroes(矩阵置零) 数组/medium

文章目录1.Description2.Example3.Solution1.使用标记数组2.使用两个标记变量 1.Description 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 进阶: 一个直观的解决方案是使用 O(mn) 的额外空间,但这并不是一个好的解决方案。 一个简单的改进方案是使用 O(m + n) 的额外空间,但这仍然不是最好的解决方案。 你能想出一个仅使用常量空间的解决方案吗? 2.Example 输入:matri

押切徹的博客 252

【LeetCode】解题73:Set Matrix Zeroes

LeetCode解题 73:Set Matrix Zeroes Problem 73: Set Matrix Zeroes [Medium]解题思路Solution (Java) Problem 73: Set Matrix Zeroes [Medium] Given a m x n matrix, if an element is 0, set its entire row and column...

Fayedily的博客 205

[LeetCode][73] Set Matrix Zeroes

题目大意:给定一个矩阵 如果矩阵中出现元素0 则元素所在的行和列都被清空为0 Emmmm 本题算法很简单,所以采用std::multimap 目的是熟悉这个容器 算法当然不是很快。。。毕竟O(n3) /* * @lc app=leetcode id=73 lang=cpp * * [73] Set Matrix Zeroes * * https://leetcode.com/prob...

OCEANtroye的博客 288

Leetcode解题报告:73. Set Matrix Zeroes

题意: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution

wengyunpeng的博客 352

Leetcode刷题记—— 73. Set Matrix Zeroes(设置矩阵0)

一、题目叙述: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Subscribe to see which companies ask

爱胡椒的小白兔呢 874

LeetCode73 Set Matrix Zeroes

题目: Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.(Medium) 分析: 题意很简单,就是把为0的元素所在的行和列都置0; 首先不能直接边循环边做,这样会造成很多本来不是0的元素被置0之后,在后续判断中将它的行列也置0; 所以简单的方法是建立两...

weixin_30273501的博客 93
上一篇: 【leetcode】71.(Medium)Simplify Pathes
下一篇: 【leetcode】74. (Medium)Search a 2D Matrix
AXIMI
博客等级 码龄10年 53粉丝 455原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值