Leetcode 59. Spiral Matrix II
来源:互联网 发布:淘宝做图片视频教程 编辑:程序博客网 时间:2024/05/21 03:16
public class Solution { public int[][] generateMatrix(int n) { int[][] res = new int[n][n]; int up = 0, right = n-1, down = n-1, left = 0, elem = 1; while (true) { for (int col=left; col<=right; col++) res[up][col] = elem++; if (++up > down) break; for (int row=up; row<=down; row++) res[row][right] = elem++; if (--right < left) break; for (int col=right; col>=left; col--) res[down][col] = elem++; if (--down < up) break; for (int row=down; row>=up; row--) res[row][left] = elem++; if (++left > right) break; } return res; }}
0 0
- [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
- 59. Spiral Matrix II LeetCode
- [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
- Matlab与线性代数 -- 矩阵的连接
- Linux命令总结
- summary of 2016
- C/C++框架和库
- windows下开发android必备工具
- Leetcode 59. Spiral Matrix II
- java jsoup解析requert请求中的xml格式数据
- 2016年,续航新能量
- Bower introduction
- Gson 官方文档
- Spring 框架参考文档(五)-The Web之Web MVC 框架
- CentOS 7搭建SVN服务器
- 69 个经典 Spring 面试题和答案
- linux下的粘滞位