LeetCode力扣之Spiral Matrix

海康VM加密狗无法识别常见问题排查 阅读详情

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 ]
]

You should return [1,2,3,6,9,8,7,4,5].

package leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lxw, liwei4939@126.com on 2018/3/9.
 */
public class L054_Spiral_Matrix {

    public List<Integer> spiralOrder(int[][] matrix){

        List<Integer> res = new ArrayList<>();

        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return res;
        }

        int tR = 0;
        int tC = 0;
        int dR = matrix.length - 1;
        int dC = matrix[0].length - 1;


        while (tR <= dR && tC <= dC){
            printEdge(matrix, res, tR++, tC++, dR--, dC --);
        }
        return res;
    }

    private void printEdge(int[][] matrix, List<Integer> res, int tR, int tC,
                      int dR, int dC){
        if (tR == dR){
            for (int i =tC; i <= dC; i++){
                res.add(matrix[tR][i]);
            }
        } else if (tC == dC){
            for (int i = tR; i <= dR; i++){
                res.add(matrix[i][tC]);
            }
        } else {
            int curR = tR;
            int curC = tC;

            while (curC != dC){
                res.add(matrix[tR][curC]);
                curC ++;
            }
            while (curR != dR){
                res.add(matrix[curR][dC]);
                curR ++;
            }
            while (curC != tC){
                res.add(matrix[dR][curC]);
                curC--;
            }
            while (curR != tR){
                res.add(matrix[curR][tC]);
                curR--;
            }
        }
    }

    public static void main(String[] args){
        L054_Spiral_Matrix tmp = new L054_Spiral_Matrix();
        int[][] matrix = new int[][]{{1, 2, 3},{4, 5, 6},{7, 8, 9}};
        List<Integer> res = tmp.spiralOrder(matrix);
        System.out.println(res);
    }
}

SAP中贸易伙伴的应用原理简析 公司也称为贸易伙伴,是出具合并报表的组织单位,可以为客户和供应商分配公司(贸易伙伴),用于识别集团内关闻公司间的业务往来,在编制合并报表时进行往来账务的计算处理。 如下图某贸易伙伴公司(关联方名称G0059)在我方公司的SAP系统中有多重身份(即是供应商,又是客户)。那么在我方公司SAP系统中建立起公司(贸易伙伴),并关联到供应商和客户主数据中。之后,就可以通过G0059这个贸易伙伴名称来识别与该贸易伙伴间的往来业务。 相应的配置设定如下: 定义公司(贸易伙伴或关联方) 会计凭证中会 阅读详情

相关推荐

从仿真到实践:两级直接耦合放大电路的静态工作点协同调试指南

本文详细解析了两级直接耦合放大电路的静态工作点协同调试方法,从仿真到实践提供系统指南。重点介绍了Rc2电阻调整技巧、集电极电位测量方法及常见问题排查,帮助工程师解决各级静态工作点相互影响的难题,提升模拟电路设计效率。

weixin_29189373的博客 130

螺旋矩阵-I

12、螺旋矩阵-I spiral-matrix: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Y...

冰美式的博客 396

Token算力工厂建设方案:从GPU集群到计量计费的全链路设计

在AI应用从“租核”走向“买Token”的范式转换中,算力交付的核心指标已不再是vCPU或GPU实例,而是单位时间内的Token产出量与单Token成本。这一变化推动基础设施从资源租赁向计件生产演进,要求GPU集群、推理引擎、调度系统、计量计费等模块像工厂产线一样协同运转。本文从硬件异构混部、存储网络设计、推理引擎调优、Token网关与配额管理、稳定性治理等维度,系统拆解如何构建一座可量化、可计费、可扩展的Token算力工厂,并给出分三期落地的推进节奏,帮助架构师与技术管理者在AI基础设施建设中实现成本可控

weixin_29095587的博客 282

L59.Spiral_Matrix_II

思路类似于54.Spinal_Matrix,旋转着填满矩阵 时间复杂度:O(N) C++代码: class Solution { enum dir { DOWNLEFT, UPRIGHT }; public: vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; generateMatrix(int n) { if (n == 0) return {}; if (n =...

qq_42263831的博客 191

AI量化投资开源平台——Qlib(微矿)的学习使用笔记(随缘更新)

Qlib 涵盖了量化投资的全过程,为用户的 AI 算法提供了高性能的底层基础架构,从框架设计上让用户可以更容易地应用 AI 算法来辅助解决量化投资的各个关键问题(例如 Alpha 预测,风险预测,市场动态性建模)。本文旨在记录一些面向初学者的基础内容。

in_void的博客 3141

S905L3B机顶盒刷Armbian:从安卓Root到eMMC全攻略

在嵌入式开发与轻量级服务器搭建中,ARM架构设备因其低功耗和高性价比备受关注。晶晨S905L3B作为运营商机顶盒的主流芯片,通过刷写Armbian系统可将其改造为ARM小服务器。其原理是利用Amlogic芯片的uboot引导机制,将Linux系统写入eMMC存储,从而脱离原厂安卓限制。这一方案的技术价值在于以极低成本实现Docker容器、下载机、轻量数据库等服务的部署,应用场景涵盖家庭网络广告过滤、智能家居控制、复古游戏机等。本文以CM311-1S为例,详细拆解从安卓9 Root到Armbian写入eMMC

weixin_31476015的博客 351

Spiral Matrix

题目大意:顺时针遍历矩阵 class Solution { public: vector spiralOrder(vector > &matrix) { vector result; if(matrix.empty() || matrix[0].empty()) { return result; }

涛涛不解 475

电动汽车整车控制器 UDS诊断功能开发调试优化方法

摘要:通过某电动汽车VCU开发过程中,UDS诊断功能的调试,发现一些测试中存在的问题,比如覆盖度不够、效率低下等,提出了相应的优化方法,并经过测试验证其可行性,此方法亦可推广应用至BMS、HCM等其他控制器的UDS诊断开发调试过程中。希望能给相关技术人员带来参考和帮助。

qq_43011586的博客 2150

LeetCode力扣之Spiral Matrix II

Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]...

LeeWei 179

电磁仿真软件CST2020 下载链接及安装破·解教程笔记

众所周知,配环境是安装软件最头疼的事情。CST2020我调了一上午,网上现有的安装教程良莠不齐,很难有一篇文章能够全流程的讲述安装过程以及遇到的问题。正好今天我要给另一台电脑装软件,借此机会把安装过程记录下来,以供将来使用和他人借鉴。 首先提供下载地址: 百度网盘 链接:https://pan.baidu.com/s/1cDJZelufj-nliUfekMNpEA 提取码:8ihx 附: 根据二○○二年一月一日《计算机软件保护条例》规定:为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软

weixin_42845306的博客 3万+

SCL3400-D01双轴高精度倾角计

简介 两轴高精度加速度计,提供两个模式。 ±30° with 10 Hz LPF ±90° with 40 Hz LPF Resolution up to 32768 LSB/g Ultra-low 0.0009°/√Hz noise density 这款传感器是替换之前村田的停产的模拟量系列的芯片,正在测试中,具体效果大伙可以评测。 一、引脚连接图 引脚图兼容SCL3300 二、SPI接口 1.SCL3300和SCL3400略有区别如下图 左边为SCL3...

专注惯导领域 3819

54. Spiral Matrix(螺旋矩阵)解法(C++ & 注释)

54. Spiral Matrix(螺旋矩阵)1. 题目描述2. 按层遍历(Layer-by-Layer)2.1 解题思路2.2 实例代码 1. 题目描述 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 输出: [1,2,3,6,9,8,7,4,5] 示例 2: 输入: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10

主要研究图形学相关领域 1185

SAP-ABAP:SAP HANA性能神器FDA:是极速查询的引擎,也是CPU过载的元凶

在SAP S/4HANA的世界里,有一个被ABAP开发者们既爱又怕的特性——Fast Data Access(FDA),它能将性能提升百倍,也能让CPU瞬间飙升。本文将带您全面解剖这一核心机制。

baidu_35680696的博客 854

【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

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Leetcode 59. Spiral Matrix II

题目 解法 这道题目其实跟这道https://blog.csdn.net/qq_37821701/article/details/112093118一模一样。参考这道题目里面的第二种解法 class Solution: def generateMatrix(self, n: int) -> List[List[int]]: cnt = 1 dirs = [[0,1],[1,0],[0,-1],[-1,0]] row = 0 co

qq_37821701的博客 473

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Leetcode之 Spiral Matrix 问题

问题描述: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. 示例: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You should return [1,2,3,6,9,8,7,4,

漫漫学习路 360

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LeetCode //C - 885. Spiral Matrix III

Article Summary The task requires starting at the grid's starting point (rStart, cStart), traversing all grid locations in a clockwise spiral (including moving beyond the grid's bounds), ultimately returning the coordinates of all visited grid locations. T

Made in Code 1196

LeetCode 54. Spiral Matrix

LeetCode 54. Spiral Matrix 循环输出矩阵元素,中等难度题目,查数要认真。 Solution1:我的答案 class Solution { public: vector&amp;lt;int&amp;gt; spiralOrder(vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; matrix) { if (!matrix.size()

Allenlzcoder的博客 512

LeetCode解题报告—— Group Anagrams & Pow(x, n) & Spiral Matrix

1.Group Anagrams Given an array of strings, group anagrams together. For example, given:["eat", "tea", "tan", "ate", "nat", "bat"], [ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ]...

dbvz4901的博客 162

LeetCode 59. Spiral Matrix II

LeetCode 59. Spiral Matrix II Solution1:我的答案 思路和第54题差不多,就是有点慢。。。。 class Solution { public: vector&lt;vector&lt;int&gt;&gt; generateMatrix(int n) { if (n == 1) return {{1}}; vect...

Allenlzcoder的博客 916

LeetCode Spiral Matrix

将一个矩阵中的内容螺旋输出。

DRFish 1240

【LeetCode】#54螺旋矩阵(Spiral Matrix)

【LeetCode】#54螺旋矩阵(Spiral Matrix) 题目描述 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 示例 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 输出: [1,2,3,6,9,8,7,4,5] 示例 2: 输入: [ [1, 2, 3, 4], [5, ...

weixin_43858604的博客 109

力扣(LeetCode)59. Spiral Matrix II(螺旋矩阵2)

/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */ int** generateMatrix(int n, int

s_w_s_的博客 205

leetcode学习笔记59 Spiral Matrix II

leetcode学习笔记59问题思考方法1方法2 问题 Spiral Matrix II Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] Example 2: Input: n = 1 Output: [[1]] Constr

kuma的博客 168

LeetCode Algorithm 0059 - Spiral Matrix II (Medium)

0059 - Spiral Matrix II (Medium),Related Topics: Array

DarkRabbit的专栏 388

NYUer | LeetCode59 Spiral Matrix II

NYUer | LeetCode59 Spiral Matrix II

Moses_SU的博客 192
上一篇: LeetCode力扣之46_Permutations
下一篇: LeetCode力扣之Jump Game
Lee_Wei4939
博客等级 码龄11年 114粉丝 184原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值