LeetCode-566. Reshape the Matrix
来源:互联网 发布:php个人博客网站代码 编辑:程序博客网 时间:2024/06/05 05:28
耗时5ms,解决思路:
1. 遍历数组先转换为一维数组或存在队列里以便重组
2. 从队列中取数,存入r,c的二维数组中。
public class Solution { public int[][] matrixReshape(int[][] nums, int r, int c) { int[][] res=new int[r][c]; if(nums.length==0 || r*c!=nums.length*nums[0].length) return nums; int count=0; Queue<Integer> queue=new LinkedList<>(); for(int i=0;i<nums.length;i++) { for(int j=0;j<nums[0].length;j++) { queue.add(nums[i][j]); } } for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { res[i][j]=queue.remove(); } } return res; }}
阅读全文
0 0
- leetcode 566. Reshape the Matrix
- LeetCode 566. Reshape the Matrix
- [LeetCode]566. Reshape the Matrix
- [leetcode]566. Reshape the Matrix
- LeetCode:566. Reshape the Matrix
- leetcode 566. Reshape the Matrix
- LeetCode | 566. Reshape the Matrix
- leetcode-566. Reshape the Matrix
- LeetCode 566.Reshape the Matrix
- LeetCode: 566. Reshape the Matrix
- LeetCode-566. Reshape the Matrix
- LeetCode * 566.Reshape the Matrix
- LeetCode: 566. Reshape the Matrix
- leetcode.566.Reshape the Matrix
- LeetCode 566. Reshape the Matrix
- [LeetCode] 566. Reshape the Matrix
- 【LeetCode】566. Reshape the Matrix
- [LeetCode]566. Reshape the Matrix
- 通过zclip复制内容到剪切板
- [学习笔记]Android系统功能之基础知识(传感器、无线传输与媒体硬件功能开发)
- hihocoder1239(递推)
- markdown段首空格/段首缩进问题
- oracle数据库常用的99条查询语句
- LeetCode-566. Reshape the Matrix
- CircleNumberProgressBar:显示数字的圆形进度条
- 杭电题型分类
- P-value个人理解
- PHP函数表
- LIBSVM的简易入门
- 装了新版本的JDK 打开CMD 发现还是原来的版本
- 3. Longest Substring Without Repeating Characters
- C语言青葱之路-指针练习-输入整型数组,用指针输出