【hot100篇-python刷题记录】【矩阵置零】

R5-矩阵篇

印象题,思路即可:

手动置0

无非就是行和列都置0

使用thex和they将该元素的i和y存储起来,再分别遍历thex,将所有y的位置置0

遍历they,将所有x 置0

python 复制代码
class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        m=len(matrix)
        n=len(matrix[0])
        thex=[]
        they=[]
        for i in range(m):
            for j in range(n):
                if matrix[i][j]==0:
                    thex.append(i)
                    they.append(j)
        #清除
        for i in thex:
            for j in range(n):
                matrix[i][j]=0
        
        for j in they:
            for i in range(m):
                matrix[i][j]=0
相关推荐
guoran_shini5 分钟前
LLM微调-训练垂类问答模型
python·lora·sft
basketball61612 分钟前
Python FastAPI 介绍以及常用方法
python·fastapi·vllm·ai infra
+VX:Fegn089518 分钟前
计算机毕业设计|基于springboot + vue旅游管理系统(源码+数据库+文档)
java·开发语言·vue.js·spring boot·课程设计
论文复现现场31 分钟前
企业知识库 RAG 用什么模型便宜?GLM-5.3-Flash 长文本 API 实测
python·rag·企业知识库·大模型api·glm-5.3-flash
梦在远山后1 小时前
从手写 Loop 到可恢复 Runtime:用 LangGraph、PostgreSQL Checkpoint 与 AG-UI 跑通中断恢复
python·langchain·agent
阿里嘎多学长1 小时前
2026-09-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
INGNIGHT1 小时前
270 · 电话号码的字母组合II(Trie)
linux·算法
Yolanda_20221 小时前
8.tensorboard的使用
python
2401_839080541 小时前
C++常见八股
数据结构·c++·算法
用户0332126663671 小时前
使用 Python 添加、隐藏或删除 PowerPoint 幻灯片
python