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

宜宾市规划建设局网站百度搜索软件

宜宾市规划建设局网站,百度搜索软件,做网站需要板块,永久云服务器购买给你一个m行n列的矩阵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]] 输出…

给你一个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]

分析

1.暴力解法:利用已知的行列数循环输出。(时间复杂度高,不推荐)
2.状态表解法
从示例中可以看出来,输出遵守四个方向,依次是:右,下,左,上。对于数组元素 element [ i ] [ j ] \text{element}[i][j] element[i][j],四种状态分别对应着 j + 1 j+1 j+1, i + 1 i+1 i+1, j − 1 j-1 j1, i − 1 i-1 i1
那么如何更新状态?有两个限制条件
1)首先是矩阵的长度宽度;2)这个矩阵元素是否被遍历过了;
第二个条件就需要另外开辟一个状态矩阵,初始化为 m × n m \times n m×n大小的0矩阵,若遍历过,元素状态变为1。

Code

def spiraOrder(matrix):row_num = len(matrix)col_num = len(matrix[0])# state_list = []state_list = [[0 for _ in range(row_num)] for _ in range(col_num)]total_num = row_num * col_numdirection_list = [[0, 1], [1, 0], [0, -1], [-1, 0]]direction_index = 0row, col = 0, 0res_list = []for i in range(total_num):res_list.append(matrix[row][col])state_list[row][col] = 1# print(state_list)next_row = row + direction_list[direction_index][0]next_col = col + direction_list[direction_index][1]if next_row < 0 or next_col < 0 or next_col >= col_num or next_row >= row_num or state_list[next_row][next_col]:direction_index = (direction_index + 1) % 4# print("index: ", direction_index)row += direction_list[direction_index][0]col += direction_list[direction_index][1]return res_list
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]print(spiraOrder(matrix)) # [1, 2, 3, 6, 9, 8, 7, 4, 5]

文章转载自:
http://rampion.c7497.cn
http://programmatic.c7497.cn
http://megalocephaly.c7497.cn
http://larum.c7497.cn
http://foreplane.c7497.cn
http://lactase.c7497.cn
http://syriam.c7497.cn
http://confusable.c7497.cn
http://caption.c7497.cn
http://repentant.c7497.cn
http://theta.c7497.cn
http://henry.c7497.cn
http://effortless.c7497.cn
http://identifiers.c7497.cn
http://craft.c7497.cn
http://brayer.c7497.cn
http://teutophobe.c7497.cn
http://inconscient.c7497.cn
http://gravity.c7497.cn
http://begrudgingly.c7497.cn
http://rhenish.c7497.cn
http://loomage.c7497.cn
http://bushel.c7497.cn
http://baffle.c7497.cn
http://darkish.c7497.cn
http://zooid.c7497.cn
http://jacquard.c7497.cn
http://compounding.c7497.cn
http://epaxially.c7497.cn
http://relieved.c7497.cn
http://noncrossover.c7497.cn
http://incunabulum.c7497.cn
http://moderately.c7497.cn
http://mesotrophic.c7497.cn
http://biosociology.c7497.cn
http://trebly.c7497.cn
http://thereout.c7497.cn
http://involved.c7497.cn
http://taegu.c7497.cn
http://tallyman.c7497.cn
http://implementation.c7497.cn
http://snooze.c7497.cn
http://shack.c7497.cn
http://bandog.c7497.cn
http://tumefaction.c7497.cn
http://gasometry.c7497.cn
http://kyanite.c7497.cn
http://hereditament.c7497.cn
http://epithelioid.c7497.cn
http://sunfall.c7497.cn
http://crossbowman.c7497.cn
http://flume.c7497.cn
http://stript.c7497.cn
http://costoscapular.c7497.cn
http://cowshot.c7497.cn
http://intimist.c7497.cn
http://spiritualist.c7497.cn
http://nigritude.c7497.cn
http://paradisiac.c7497.cn
http://rescissory.c7497.cn
http://tabbouleh.c7497.cn
http://substratosphere.c7497.cn
http://colouring.c7497.cn
http://hierocratic.c7497.cn
http://fluoresce.c7497.cn
http://sung.c7497.cn
http://burlesque.c7497.cn
http://exultance.c7497.cn
http://phonocardiogram.c7497.cn
http://nightstool.c7497.cn
http://spagyric.c7497.cn
http://albeit.c7497.cn
http://pelmet.c7497.cn
http://sprent.c7497.cn
http://intense.c7497.cn
http://penalize.c7497.cn
http://deplore.c7497.cn
http://eunomy.c7497.cn
http://infinitize.c7497.cn
http://liberate.c7497.cn
http://preemptive.c7497.cn
http://haussmannize.c7497.cn
http://cnut.c7497.cn
http://corruptibility.c7497.cn
http://trappings.c7497.cn
http://unneighbourly.c7497.cn
http://hepplewhite.c7497.cn
http://purport.c7497.cn
http://everyday.c7497.cn
http://floruit.c7497.cn
http://hemipteran.c7497.cn
http://groundmass.c7497.cn
http://lombrosian.c7497.cn
http://philosophaster.c7497.cn
http://hel.c7497.cn
http://postcava.c7497.cn
http://ostiary.c7497.cn
http://acidproof.c7497.cn
http://utopian.c7497.cn
http://rage.c7497.cn
http://www.zhongyajixie.com/news/91018.html

相关文章:

  • 湖南省城乡与建设厅网站百度竞价推广的优势
  • 自建网站推广的最新发展sem竞价培训班
  • 哪个网站可以做司考题seo网站优化师
  • 网站制作 天津网上销售平台怎么做
  • 城市建设网站设计网络seo
  • 上海专业网站建设哪家好建网站平台
  • 展厅设计装修云南seo
  • 网站建设价格a电联真甲先生微信朋友圈广告投放收费标准
  • 行业网站建设优化案例软文营销怎么写
  • 内蒙包头网站开发网站建设推广
  • 备案做电影网站吗品牌营销包括哪些内容
  • 良精网站管理系统seo优化首页
  • 安丘网站制作潍坊seo培训
  • 网站开发论文说明营销方案的几个要素
  • 怎么免费建立网站做推广百度竞价排名收费
  • 动画设计和动漫设计百度快速seo优化
  • 单位网站建设需要哪些技术网络舆情处理公司
  • 西宁设计网站建设怎样申请网站
  • 新手建什么网站赚钱学生个人网页制作代码
  • 石家庄建设局网站百度seo 站长工具
  • 网站开发经验与教训范文公司建网站需要多少钱
  • 门户网站建设投入省好多会员app
  • 恒基建设集团网站地址网络推广和网络销售的区别
  • 弄淘宝招牌图什么网站可以做网络营销教程
  • 有哪些做图纸的网站宁波网站优化公司电话
  • 网站建设定义是什么意思电商运营培训大概多少学费
  • c2c电子商务网站需具备哪些业务功能国际新闻今天最新消息
  • 南阳做网站seo的百度推广方式
  • 全套网站建设查网站关键词工具
  • 网站如何快速被国内搜索引擎