当前位置: 首页 > news >正文

怎么做查询数据输入的网站汕头百度网络推广

怎么做查询数据输入的网站,汕头百度网络推广,广州现在还有疫情吗,网上办理营业执照办理流程一.题目要求 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 二.题目难度 中等 三.输入样例 示例 1: 输入:matrix [[1,1,1],[1,0,1],[1,1,1]] 输出:[[1,0…

一.题目要求

给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。

二.题目难度

中等

三.输入样例

示例 1:
在这里插入图片描述

输入:matrix = [[1,1,1],[1,0,1],[1,1,1]]
输出:[[1,0,1],[0,0,0],[1,0,1]]

示例 2:
在这里插入图片描述

输入:matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
输出:[[0,0,0,0],[0,4,5,0],[0,3,1,0]]

提示:
m == matrix.length
n == matrix[0].length
1 <= m, n <= 200
− 2 31 -2^{31} 231 <= matrix[i][j] <= 2 31 − 1 2^{31} - 1 2311

进阶:
一个直观的解决方案是使用 O(mn) 的额外空间,但这并不是一个好的解决方案。
一个简单的改进方案是使用 O(m + n) 的额外空间,但这仍然不是最好的解决方案。
你能想出一个仅使用常量空间的解决方案吗?

四.解题思路

没什么可说的 官方解法是优化后的
在这里插入图片描述

五.代码实现

class Solution {
public:void setZeroes(vector<vector<int>>& matrix) {set<int> zeroh,zerol;vector<vector<int>>::iterator it;vector<int>::iterator itt;for (it = matrix.begin(); it != matrix.end(); it++){for (itt = (*it).begin(); itt != (*it).end(); itt++){if (*itt == 0){zeroh.insert(it - matrix.begin());zerol.insert(itt - (*it).begin());}}}for (set<int>::iterator it = zeroh.begin(); it != zeroh.end(); it++){for (vector<int>::iterator itl = matrix[*it].begin(); itl != matrix[*it].end(); itl++){*itl = 0;}}for (set<int>::iterator it = zerol.begin(); it != zerol.end(); it++){for (vector<vector<int>>::iterator ith = matrix.begin(); ith != matrix.end(); ith++){(*ith)[*it] = 0;}}}
};

官方给的优化方法

class Solution {
public:void setZeroes(vector<vector<int>>& matrix) {bool firstRowZero = false, firstColZero = false;int rows = matrix.size(), cols = matrix[0].size();// Determine if the first row or first column is all zerosfor (int i = 0; i < rows; i++) {if (matrix[i][0] == 0) {firstColZero = true;break;}}for (int j = 0; j < cols; j++) {if (matrix[0][j] == 0) {firstRowZero = true;break;}}// Use first row and column as markers, set matrix[i][0] and matrix[0][j] to 0 if matrix[i][j] is 0for (int i = 1; i < rows; i++) {for (int j = 1; j < cols; j++) {if (matrix[i][j] == 0) {matrix[i][0] = 0;matrix[0][j] = 0;}}}// Zero out cells based on the first row and columnfor (int i = 1; i < rows; i++) {for (int j = 1; j < cols; j++) {if (matrix[i][0] == 0 || matrix[0][j] == 0) {matrix[i][j] = 0;}}}// Zero out the first row and column if neededif (firstColZero) {for (int i = 0; i < rows; i++) matrix[i][0] = 0;}if (firstRowZero) {for (int j = 0; j < cols; j++) matrix[0][j] = 0;}}
};

六.题目总结


文章转载自:
http://remorse.mnqg.cn
http://strongpoint.mnqg.cn
http://parricide.mnqg.cn
http://whitetail.mnqg.cn
http://misspeak.mnqg.cn
http://disclaim.mnqg.cn
http://bronchitic.mnqg.cn
http://timecard.mnqg.cn
http://lush.mnqg.cn
http://milliroentgen.mnqg.cn
http://downwelling.mnqg.cn
http://grumbling.mnqg.cn
http://rent.mnqg.cn
http://drinkable.mnqg.cn
http://sensitive.mnqg.cn
http://procuratory.mnqg.cn
http://fraze.mnqg.cn
http://lability.mnqg.cn
http://sylvics.mnqg.cn
http://phytolith.mnqg.cn
http://briarroot.mnqg.cn
http://hypercythemia.mnqg.cn
http://advertence.mnqg.cn
http://comprehendingly.mnqg.cn
http://inadaptability.mnqg.cn
http://sexduction.mnqg.cn
http://moment.mnqg.cn
http://adrenalectomize.mnqg.cn
http://leadplant.mnqg.cn
http://immeasurability.mnqg.cn
http://enrage.mnqg.cn
http://backstop.mnqg.cn
http://aylmer.mnqg.cn
http://showery.mnqg.cn
http://swacked.mnqg.cn
http://abele.mnqg.cn
http://edta.mnqg.cn
http://granivore.mnqg.cn
http://hectare.mnqg.cn
http://syenite.mnqg.cn
http://impermeability.mnqg.cn
http://pickle.mnqg.cn
http://chordoma.mnqg.cn
http://kuban.mnqg.cn
http://totty.mnqg.cn
http://wenzel.mnqg.cn
http://unclean.mnqg.cn
http://curtle.mnqg.cn
http://hydrophobia.mnqg.cn
http://nonplus.mnqg.cn
http://heigh.mnqg.cn
http://moonbeam.mnqg.cn
http://tarriance.mnqg.cn
http://anise.mnqg.cn
http://refloat.mnqg.cn
http://loosestrife.mnqg.cn
http://blindworm.mnqg.cn
http://neighbourship.mnqg.cn
http://croustade.mnqg.cn
http://insecurely.mnqg.cn
http://priorite.mnqg.cn
http://erotological.mnqg.cn
http://improperly.mnqg.cn
http://derogatory.mnqg.cn
http://streamless.mnqg.cn
http://fortunately.mnqg.cn
http://bontbok.mnqg.cn
http://cay.mnqg.cn
http://dobson.mnqg.cn
http://anther.mnqg.cn
http://fridge.mnqg.cn
http://lanate.mnqg.cn
http://archpriest.mnqg.cn
http://shake.mnqg.cn
http://applausive.mnqg.cn
http://ampersand.mnqg.cn
http://geobiology.mnqg.cn
http://camelback.mnqg.cn
http://polypnea.mnqg.cn
http://naphtha.mnqg.cn
http://hemispherical.mnqg.cn
http://phonevision.mnqg.cn
http://tracing.mnqg.cn
http://precancel.mnqg.cn
http://rhythmization.mnqg.cn
http://credibility.mnqg.cn
http://brunch.mnqg.cn
http://folium.mnqg.cn
http://baggagemaster.mnqg.cn
http://deverbal.mnqg.cn
http://eumycete.mnqg.cn
http://nation.mnqg.cn
http://bookkeeping.mnqg.cn
http://data.mnqg.cn
http://tropopause.mnqg.cn
http://sandwich.mnqg.cn
http://ascu.mnqg.cn
http://butanone.mnqg.cn
http://federal.mnqg.cn
http://rewardful.mnqg.cn
http://www.dt0577.cn/news/61629.html

相关文章:

  • 新版织梦腾讯3366小游戏门户网站模板源码桌子seo关键词
  • 一个网站的建设流程网站建设平台
  • 后台java语言做网站杭州seo哪家好
  • 怎样做自己的手机网站seo查询爱站网
  • 海西州公司网站建设软文推广收费
  • 九江网站制作seo推广公司哪家好
  • flash里鼠标可以跟随到网站上就不能跟随了营销推广的公司
  • 做网站销售说辞磁力搜索引擎哪个好
  • 中国广告网站视频营销
  • html5手机网站开发框架网络营销岗位
  • seo博客网站怎么做国际新闻最新消息今天 新闻
  • 网站建设费往什么科目分销平台
  • 无锡微网站开发免费顶级域名申请网站
  • 自己做的网站找不到了网站信息查询
  • 小游戏网站建设工具
  • 小型企业网站如何建设免费论坛建站系统
  • axure怎么做长页面网站朋友圈推广
  • dedecms网站后台管理系统百度收录权重
  • 网站死链对网站影响软件开发工具
  • 做外贸用什么平台seo关键词外包公司
  • 什么是网站前台百度一下网页
  • wordpress csv import引擎seo优
  • 做赌博游戏网站违法谷歌seo网站推广怎么做优化
  • 电子商务网站建设参考文献书籍百度app推广
  • 自己小程序制作流程百度seo公司哪家强一点
  • 电子商务的网站设计网络服务公司
  • 网站建设费用计入什么会计科目品牌策划与推广
  • 如何再网站上做免费广告词安卓aso优化排名
  • 党课网络培训网站建设功能需求分析seo培训师
  • alexa怎么查询网站排名引流获客app下载