LeetCode 54. Spiral Matrix

基于 YOLOv8 的自动驾驶车辆障碍物检测与避障路径规划 本文探讨基于YOLOv8的自动驾驶车辆障碍物检测与避障路径规划系统。在感知层面,采用YOLOv8模型实现多类别障碍物识别,结合单目视觉距离估计和ByteTrack多目标跟踪算法,完成障碍物的稳定检测与运动状态估计。在路径规划层面,设计分层规划架构,融合全局路径规划与局部避障算法,重点实现Frenet坐标系下的采样优化算法和基于模型预测控制的实时避障轨迹生成。通过完整的代码实现与仿真实验,验证系统在复杂交通场景下的有效性与实时性,为自动驾驶开发者提供从理论到实践的完整技术参考。 关键词:YOLOv8;自动驾驶 阅读详情

一  题目

  Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

Example 1:

Input:
[
 [ 1, 2, 3 ],
 [ 4, 5, 6 ],
 [ 7, 8, 9 ]
]
Output: [1,2,3,6,9,8,7,4,5]

Example 2:

Input:
[
  [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9,10,11,12]
]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]

二 分析

medium级别,求螺旋式输出M*N矩阵的内容。

所谓螺旋式就容易理解,顺时针嘛,处理4个边,分别方向就是从左到右遍历行,从上到下遍历列,再从右到左遍历行,再从下往上遍历列。

因此定义了上下左右四个变量表示四个角。每次循环,都对应加或者减。遍历前面判断res是否满了。

代码如下:

public static void main(String[] args) {
		int[][] matrix1={
				{7},
				{9},
				{6}
		};
		List<Integer> res1 =  spiralOrder(matrix1);
		System.out.println(JSON.toJSON( res1 ));
		
		int[][] matrix={
				{1,2,3},
				{4,5,6},
				{7,8,9}
		};
		List<Integer> res =  spiralOrder(matrix);
		System.out.println(JSON.toJSON( res ));
	}
	
	 public static List<Integer> spiralOrder(int[][] matrix) {
		 List<Integer> res = new ArrayList<>();
		 //conner case
	     if(matrix == null || matrix.length == 0){
	        return res;
	     }
	     //行
		 int m = matrix.length;
		 //列
		 int n = matrix[0].length;
	     //定义边界四个角
		 int left=0;int right= n-1;int up =0; int down= m-1; 
		 
		 while(res.size() < m*n ){
			 
			 if(up<m){
				 //从左往右:遍历列
				 for(int i= left;i<=right;i++ ){
					 res.add( matrix[up][i]);					 
				 }
				 up++;
			 }
			 //从上往下:遍历行
			 if(res.size() < m*n){
				 for(int i=up;i<=down;i++){
					 res.add( matrix[i][right]);
				 }
				 right--;
			 }
			 //从右往左:遍历列
			 if( res.size() < m*n){
				 
				 for(int i= right;i>=left;i--){
					 res.add(matrix[ down][i ] );
				 }
				 down--;
			 }
			 //从下到上:遍历行
			 if(res.size() < m*n){
				 for(int i=down;i>=up;i--){
					 res.add(matrix[ i][left] );
				 }
				 left++;
			 }
			 
		 }
		 		 
		return res;		 
	 }

Runtime: 0 ms, faster than 100.00% of Java online submissions for Spiral Matrix.

Memory Usage: 34.7 MB, less than 100.00% of Java online submissions for Spiral Matrix.

时间复杂度:O (M*N)

 

 

SAP S/4HANA Cloud 管理员业务角色创建实战:基于 SAP_BR_ADMINISTRATOR 模板的一站式指南 摘要:SAP S/4HANA Cloud新系统初始登录时常见Fiori Launchpad无磁贴的问题,这是由于缺乏合适的业务角色分配。本文介绍了通过预交付的SAP_BR_ADMINISTRATOR模板创建管理员角色的完整流程,包括业务用户、业务角色和业务目录的核心概念解析。重点说明了直接使用模板的风险,并提供了从模板创建自定义管理员角色的详细步骤(4.1-4.3),以及权限限制设置的注意事项。文中还分享了一个实际项目案例,强调正确配置管理员角色对后续权限体系建设的关键作用。(149字) 阅读详情

相关推荐

使用LoRa远程控制路灯(PWM调光以及LoRaWAN单播、组播、广播)

PWM调光 1、使用有pwm波输出的引脚,本例子使用timer0,PA0引脚; 2、由于timer时钟的原因,mcu不能进入休眠; 3、主控使用EFM32,代码实现如下: #define MAX_PULSE (CPU_FREQ/1000-1) #define UNIT_PULSE MAX_PULSE/100 //单位脉宽 void pwminit(void) { ...

freemote的博客 2951

【LeetCode】解题54:Spiral Matrix

LeetCode解题 54:Spiral Matrix Problem 54: Spiral Matrix [Medium]解题思路Solution (Java)修改过程 Problem 54: Spiral Matrix [Medium] Given a matrix of m x n elements (m rows, n columns), return all elements of th...

Fayedily的博客 259

1999年-2022年 上市公司-企业劳动生产率数据(原始数据、代码、最终结果、参考文献)

上市公司企业劳动生产率数据集为企业和市场参与者提供了一个深入分析企业生产效率和劳动效益的工具。通过这些数据,企业可以不断探索创新的发展模式和管理方式,努力提高生产效率,为提升市场竞争力和盈利能力做出贡献。数据名称:上市公司-企业劳动生产率数据数据年份:1999-2022年数据来源:国泰安数据库1999年-2022年 上市公司-企业劳动生产率数据(原始数据、代码、最终结果、参考文献)

2401_84585615的博客 887

LeetCode54——Spiral Matrix

LeetCode54——Spiral Matrix 还是用图来表述: 从左上开始,按照箭头的顺序,进行4个for循环,完成一圈,一共用count = min(row,col)/2  圈。 注意最后的红色箭头,如果行数和列数中较小的数是奇数,就会出现上述情况。 这个时候咱们在最后补上就好 代码: class Solution { public: vector spiralOrd

上善若水 2152

SPL06气压温度传感器SPI驱动与补偿算法详解

气压传感器与温度传感器是嵌入式环境感知系统的核心组件,其测量精度高度依赖于MEMS芯片的校准参数与非线性补偿机制。SPL06作为集成式高精度数字传感器,采用24位Σ-Δ ADC与片内补偿引擎,需结合唯一出厂校准系数(即‘芯片指纹’)进行多阶数学修正,才能将原始ADC值转化为符合计量要求的帕斯卡(Pa)与摄氏度(℃)物理量。该过程涵盖SPI通信协议解析、寄存器时序控制、大端数据拼接、二进制补码处理及浮点/定点混合运算等典型嵌入式工程实践。广泛应用于无人机高度计、智能穿戴海拔监测与IoT气象终端中。

weixin_34640289的博客 147

4-都2026年了,嵌入式发展前景怎么样,还适合入行吗?

本文系统分析了嵌入式行业的发展前景,指出到2026年嵌入式将迎来由"万物智联"驱动的黄金周期。文章回顾了嵌入式技术的四个演进阶段,从专用计算机到AIoT时代,强调其技术积累的延续性。作者从人才流向、产业智能化转型、高校新增专业等角度论证嵌入式行业的蓬勃发展,并提出"铁三角"模型分析其驱动力和护城河。最后给出职业发展路径建议,认为嵌入式适合长期主义者,在智能汽车、边缘计算等领域有广阔前景。文章建议读者抓住产业升级机遇,选择这一稳定且有复利效应的技术赛道。

指尖动听知识库 406

【LeetCode】54. Spiral Matrix

问题描述https://leetcode.com/problems/spiral-matrix/#/description Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following

zgljl2012的专栏 1093

全志A133的AndroidSDK

本小节来学习如何下载全志安卓SDK,SDK的目录,编译和烧录提示:以下是本篇文章正文内容,下面案例可供参考以上就是整个SDK的目录和编译烧录,目的在于让初学者快速了解整个源码的目录和编译出镜像喜欢就订阅吧。

qq_24093081的博客 4076

[LeetCode 54] Spiral Matrix

题目链接:spiral-matrix import java.util.ArrayList; import java.util.List; /** * Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For

瓦尔登湖 1035

利用autojs制作抢购支付宝消费劵的手机脚本

前期准备工作 1.打开支付宝,点击中间的抢消费券的广告 2.点击左上角,将抢购页面添加到首页 3.查看支付宝首页是否出现消费劵 . autojs代码 "auto"; functiontaskstart(){ sleep(1000); launchApp('支付宝'); toast("正在打开支付宝应用"); sleep(1000); varxf=textContains("消费").findOne().bounds(); ...

洛阳泰山的博客 1万+

Auto.js实现视频号点赞自动化

摘要:本文介绍了一个微信视频号自动化点赞的实现方案。通过定位点赞图标和数量容器,点击点赞按钮后检测点赞数变化,若发现取消点赞则自动补点。核心代码包括:1)获取点赞容器和图标;2)记录点赞前后数量;3)判断是否误取消并补点;4)循环执行点赞和滑动页面操作。该方案解决了滑动页面可能导致误取消点赞的问题,实现了自动化批量点赞功能。文章强调仅供学习参考,提醒勿滥用该技术。

分享前端工程化、AI 应用、Agent 开发与大模型实践! 2589

leetcode矩阵类题目专杀之54. Spiral Matrix

http://www.fengchang.cc/post/3    

xunileida的专栏 267

FineReport 动态列切换统计维度

目标: 自己选择统计维度进行数据的汇总统计数据集参数实现动态列。

Davina_yu的博客 1058

leetcode 54. Spiral Matrix 、59. Spiral Matrix II

54题是把二维数组安卓螺旋的顺序进行打印,59题是把1到n平方的数字按照螺旋的顺序进行放置 54. Spiral Matrix start表示的是每次一圈的开始,每次开始其实就是从(0,0)、(1,1)这种开始的。 用endx、endy来表示每次转圈的x、y方向的终止位置,方便后面进行边界条件设置。 注意:后面start < endx && start &...

weixin_30374009的博客 120

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Leetcode 54. Spiral Matrix

题目描述:按照螺旋顺序打印矩阵。 题目链接:Leetcode 54. Spiral Matrix 思考思路:就是矩阵的一个搜索遍历,用到思想就是要dx\dy 来控制方向,正如 (0,0,-1,1)这样的方向选择,就是选择不同方向,要思考的就是什么时候转变方向。 代码如下 class Solution(object): def spiralOrder(self, matrix): ...

Za七杂⑧ 272

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

leetcode-54. Spiral Matrix

problem Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5]...

学习笔记 320

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LeetCode54.Spiral Matrix

LeetCode54.Spiral Matrix

weixin_38665509的博客 363

【C++】【LeetCode】54. Spiral Matrix && 59. Spiral Matrix II

题目Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9

zjajgyy的博客 361

Leetcode54. Spiral Matrix解题方案

Leetcode54. Spiral Matrix 题目描述 Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5] 思路 有四个方向right, left, top, bottom. direction=“right”, 当到达最右边界时,代表本行输出结束,top++, direction=“bottom”,当到达最下边界时, right–, direction = “left”,当到达最左边界是

初七的博客 163

LeetCode[54] Spiral Matrix

LeetCode[54] Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following matri...

weixin_34413357的博客 87

Leetcode 54, Spiral Matrix

Leetcode 54, Spiral Matrix, 难度medium就是按照规定顺序输出一个矩形,用四个变量保存了边界,然后对每一条边进行循环读入,处理一下相应的边界问题,复杂度为O(n),遍历了一遍数组。 以下是代码:class Solution { public: vector<int> spiralOrder(vector<vector<int>>& matrix) {

chiyiyan1586的博客 174

leetcode【54】Spiral Matrix

问题描述: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7...

fanyuwgy的博客 119

Leetcode 54 Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

无名山丘,崛起成峰 1018

leetcode54 Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

明天会更好 372

Leetcode 54. Spiral Matrix and 59. Spiral Matrix II

一:Leetcode 54. Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. 方法一:python切片 if not matrix: return [] ret = [] while matrix: ...

rainMan的博客 216

Leetcode oj java 54. Spiral Matrix

一、问题描述: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7,

Xcy的博客 339
上一篇: leetcode 53. Maximum Subarray
下一篇: leetcode 56.Merge Intervals
bohu83
博客等级 码龄20年 1930粉丝 978原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bohu83

买个馒头吃

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值