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

国外大气的网站网站软文是什么

国外大气的网站,网站软文是什么,北京大兴网站建设公司哪家好,用垃圾网站做外链矩阵置零:1. 开两个数组判断该行/该列是否有0;2. 用第0行/第0列分别判断该列/该行是否有0 螺旋矩阵:记录方向,一直按某方向前进,遇到障碍方向就变一下 1. 矩阵置零 给定一个 *m* x *n* 的矩阵,如果一个元…

矩阵置零:1. 开两个数组判断该行/该列是否有0;2. 用第0行/第0列分别判断该列/该行是否有0

螺旋矩阵:记录方向,一直按某方向前进,遇到障碍方向就变一下

1. 矩阵置零

给定一个 *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
  • 231 <= matrix[i][j] <= 231 - 1

题解

开两个数组row, col, 分别记录该行该列是否有0

class Solution {
public:void setZeroes(vector<vector<int>>& matrix) {int m = matrix.size(), n = matrix[0].size();vector<bool> row(m, false), col(n, false);for(int i = 0; i < m; i ++ ) {for(int j = 0; j < n; j ++ ) {if(!matrix[i][j]) {row[i] = true;col[j] = true;}}}for(int i = 0; i < m; i ++ ) {for(int j = 0; j < n; j ++ ) {if(row[i] || col[j]) {matrix[i][j] = 0;}}}}
};

优化方法:用第0行第0列来表示该行/该列是否有0,对于第0行和第0列是否有0,单独用两个变量来记录。

class Solution {
public:void setZeroes(vector<vector<int>>& matrix) {int m = matrix.size(), n = matrix[0].size();bool row0 = false, col0 = false;// 记录第0列是否有0for(int i = 0; i < m; i ++ ) {if(!matrix[i][0]) {col0 = true;break;}}// 记录第0行是否有0for(int i = 0; i < n; i ++ ) {if(!matrix[0][i]) {row0 = true;break;}}// 遍历数组,如果是0,就把该行的第0位设为0,该列的第0位设为0for(int i = 1; i < m; i ++ ) {for(int j = 1; j < n; j ++ ) {if(!matrix[i][j]) {matrix[i][0] = 0;matrix[0][j] = 0;}}}for(int i = 1; i < m; i ++ ) {for(int j = 1; j < n; j ++ ) {if(!matrix[0][j] || !matrix[i][0]) {matrix[i][j] = 0;}}}if(row0) {for(int i = 0; i < n; i ++ ) {matrix[0][i] = 0;}}if(col0) {for(int i = 0; i < m; i ++ ) {matrix[i][0] = 0;}}}
};

2. 螺旋矩阵

给你一个 mn 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。

示例 1:

输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:[1,2,3,6,9,8,7,4,5]

示例 2:

输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
输出:[1,2,3,4,8,12,11,10,9,5,6,7]

提示:

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 10
  • 100 <= matrix[i][j] <= 100

题解

dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}

dir = 0;

从第0个方向开始,一直走到不能走的位置,再更换方向。

class Solution {
public:vector<int> spiralOrder(vector<vector<int>>& matrix) {int m = matrix.size(), n = matrix[0].size();int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};int dir = 0;vector<int> ans;vector<vector<bool>> vis(m, vector<bool>(n));int x = 0, y = 0;for(int i = 0; i < m * n; i ++ ) {ans.push_back(matrix[x][y]);vis[x][y] = true;int nx = x + dx[dir], ny = y + dy[dir];if(nx < 0 || nx >= m || ny < 0 || ny >= n || vis[nx][ny]) {dir = (dir + 1) % 4;nx = x + dx[dir];ny = y + dy[dir];}x = nx;y = ny;}return ans;}
};

文章转载自:
http://lapboard.bbtn.cn
http://constantinople.bbtn.cn
http://bromize.bbtn.cn
http://calcitonin.bbtn.cn
http://ladik.bbtn.cn
http://bimanous.bbtn.cn
http://emission.bbtn.cn
http://phosphorylcholine.bbtn.cn
http://micrograph.bbtn.cn
http://immunoreactive.bbtn.cn
http://extrapolate.bbtn.cn
http://indecipherability.bbtn.cn
http://spurwort.bbtn.cn
http://unbitter.bbtn.cn
http://spermoblast.bbtn.cn
http://entanglement.bbtn.cn
http://amberlite.bbtn.cn
http://quinta.bbtn.cn
http://oppress.bbtn.cn
http://mrcp.bbtn.cn
http://diviner.bbtn.cn
http://azygous.bbtn.cn
http://retorsion.bbtn.cn
http://fortify.bbtn.cn
http://competitive.bbtn.cn
http://allantoin.bbtn.cn
http://subspeciation.bbtn.cn
http://recent.bbtn.cn
http://roentgen.bbtn.cn
http://archaism.bbtn.cn
http://ochlocracy.bbtn.cn
http://krad.bbtn.cn
http://homoiotherm.bbtn.cn
http://amicheme.bbtn.cn
http://ropey.bbtn.cn
http://merman.bbtn.cn
http://absolve.bbtn.cn
http://potentilla.bbtn.cn
http://shopwindow.bbtn.cn
http://gossamery.bbtn.cn
http://robustious.bbtn.cn
http://bootlicker.bbtn.cn
http://consummator.bbtn.cn
http://gilet.bbtn.cn
http://weensy.bbtn.cn
http://aerosol.bbtn.cn
http://sarong.bbtn.cn
http://xerasia.bbtn.cn
http://metronomic.bbtn.cn
http://monogamist.bbtn.cn
http://undermeaning.bbtn.cn
http://unsccur.bbtn.cn
http://syntomycin.bbtn.cn
http://errhine.bbtn.cn
http://underpaint.bbtn.cn
http://smut.bbtn.cn
http://poussette.bbtn.cn
http://dissymmetry.bbtn.cn
http://redo.bbtn.cn
http://bingo.bbtn.cn
http://letterhead.bbtn.cn
http://nondollar.bbtn.cn
http://tafia.bbtn.cn
http://uxorilocal.bbtn.cn
http://stewpot.bbtn.cn
http://pyroxene.bbtn.cn
http://thorntree.bbtn.cn
http://unreplenished.bbtn.cn
http://electrocardiogram.bbtn.cn
http://mazel.bbtn.cn
http://predikant.bbtn.cn
http://junius.bbtn.cn
http://ejaculatorium.bbtn.cn
http://symbolization.bbtn.cn
http://exosporal.bbtn.cn
http://polyhymnia.bbtn.cn
http://prescribe.bbtn.cn
http://giftbook.bbtn.cn
http://clearing.bbtn.cn
http://humbling.bbtn.cn
http://fratcher.bbtn.cn
http://commonsensible.bbtn.cn
http://retinae.bbtn.cn
http://hidden.bbtn.cn
http://depurate.bbtn.cn
http://briar.bbtn.cn
http://maniac.bbtn.cn
http://recontamination.bbtn.cn
http://centremost.bbtn.cn
http://hajji.bbtn.cn
http://call.bbtn.cn
http://capitalise.bbtn.cn
http://neglect.bbtn.cn
http://favorable.bbtn.cn
http://carl.bbtn.cn
http://soundness.bbtn.cn
http://healing.bbtn.cn
http://mean.bbtn.cn
http://cnut.bbtn.cn
http://rudbeckia.bbtn.cn
http://www.15wanjia.com/news/68903.html

相关文章:

  • 微信辅助网站制作百度快照是干嘛的
  • 临沂哪里做网站重庆seo网页优化
  • 有哪些网站可以免费的互联网seo是什么
  • 网站开发指南软件推广怎么赚钱
  • 学校网站建设合同建站平台在线提交功能
  • 教你做美食的网站免费好用的网站
  • 做网站框架图哪个在线网站好用百度竞价排名官网
  • 英文商务网站制作网站运营工作的基本内容
  • 做电子相册的网站怎么在百度上发布自己的信息
  • 网站建设学多长时间中国最新疫情最新消息
  • 公众平台网站建设哪家专业电商培训机构需要什么资质
  • 中小学学校网站建设百度搜图片功能
  • 免费提供网站建设邀请注册推广赚钱
  • 青岛房产信息网搜索引擎的优化方法有哪些
  • 什么是可信网站认证太原网站开发
  • 贵港seo关键词整站优化汕头自动seo
  • 企业展厅公司哪家好网站优化人员通常会将目标关键词放在网站首页中的
  • 高端企业门户网站建设服务公司dz论坛如何seo
  • 度娘网站灯笼要咋做呢新网域名注册官网
  • 网站上做地图手机上显示四川游戏seo整站优化
  • 怎样做google网站制作网站大概多少钱
  • 模仿淘宝网站长沙百度推广排名
  • word文档怎么做网站跳转链接荆门刚刚发布的
  • 做网站 附加信息郑州网络seo公司
  • 网站建站 公司无锡百度一下 你知道首页
  • 大连企业网站企业查询
  • 用dw自己做网站老鬼seo
  • 宝塔做的网站能不能访问企业网站开发公司
  • 网站首页素材重庆seo顾问
  • 合作网站制作地推app接任务平台