Leetcode#59||Spiral Matrix II
来源:互联网 发布:调酒师动漫知乎 编辑:程序博客网 时间:2024/04/29 17:32
public class Solution { public int[][] generateMatrix(int n) { int[][] result = new int[n][n]; int t= 0; int cnt = 1; while (t < n / 2) { // top for (int j = t; j < n - t - 1; j++) { result[t][j] = cnt++; } // right for (int i = t; i < n - t - 1; i++) { result[i][n - t - 1] = cnt++; } // bottom for (int j = n - t - 1; j > t; j--) { result[n - t - 1][j] = cnt++; } // left for (int i = n - t - 1; i > t; i--) { result[i][t] = cnt++; } t++; } if (n % 2 == 1) { result[n / 2][n / 2] = cnt; } return result; }}
0 0
- LeetCode 59: Spiral Matrix II
- [leetcode 59] Spiral Matrix II
- [LeetCode 59] Spiral Matrix II
- leetcode || 59、 Spiral Matrix II
- Spiral Matrix II - LeetCode 59
- Leetcode #59 Spiral Matrix II
- leetcode 59: Spiral Matrix II
- Leetcode#59||Spiral Matrix II
- leetcode 59:Spiral Matrix II
- 【LEETCODE】59-Spiral Matrix II
- 【leetcode】【59】Spiral Matrix II
- LeetCode 59 - Spiral Matrix II
- LeetCode 59 Spiral Matrix II
- 【LeetCode-59】Spiral Matrix II
- LeetCode 59 Spiral Matrix II
- Leetcode 59 Spiral Matrix II
- leetcode-59 Spiral Matrix II
- LeetCode 59 --- Spiral Matrix II
- Mac 电脑添加代理服务器
- java构建xml
- FOJ题目Problem 2082 过路费 (link cut tree边权更新)
- 两台linux服务器时间同步
- unity自定义宏定义以及常用自带的宏定义
- Leetcode#59||Spiral Matrix II
- Windows下的calabash安装
- Chapter4: View - The Big Nerd Ranch Guide 读书笔记
- JMeter 参数设置 变量 url
- UVA 10160 Servicing Stations
- 归档和反归档以及文件管理
- Jquery 使用记录
- 最小代价生成树
- UVA 1588 Kickdown & ACM/ICPC NEERC 2006 解题报告