Leetcode566. Reshape the Matrix
来源:互联网 发布:淘宝如何卡密自动发货 编辑:程序博客网 时间:2024/06/04 17:55
这里学习一下vector<vector<int> >的输入方法:
需要在新建一个变量vector<int> v
然后v.push_back();
之后把ans.push_back(v);
不要忘记每次清空v:
class Solution {public: vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) { int r1=nums.size(); int c1=nums[0].size(); if(r1*c1!=r*c) return nums; vector<int> a; for(int i=0;i<r1;i++){ for(int j=0;j<c1;j++){ a.push_back(nums[i][j]); } } vector<vector<int> > ans; vector<int> v; int k=0; for(int i=0;i<r;i++){ v.clear(); for(int j=0;j<c;j++){ v.push_back(a[k++]); } ans.push_back(v); } return ans; }};
阅读全文
0 0
- LeetCode566. Reshape the Matrix
- LeetCode566. Reshape the Matrix
- leetcode566. Reshape the Matrix
- leetcode566. Reshape the Matrix
- Leetcode566. Reshape the Matrix
- Reshape the Matrix---LeetCode566
- python--leetcode566. Reshape the Matrix
- 19.leetCode566:Reshape the Matrix
- LeetCode566——Reshape the Matrix
- LeetCode566:reshape matrix 解答
- Reshape the Matrix
- 566. Reshape the Matrix
- 566.Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- Reshape the Matrix
- 566. Reshape the Matrix
- 第一章 1.1 基础编程模型(我们把描述和实现算法所用到的语言特性、软件库和操作系统特性总称为基础编程模型)
- 简明易懂的动态链接库(.dll)和静态链接库(.lib)的优缺点分析
- Spring 实战学习笔记
- 一份完整的拍照后加水印代码
- Gym
- Leetcode566. Reshape the Matrix
- oracle组合索引
- Oracle与Mysql区别简述
- 图像分割“The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation”
- xlistview...
- 用python抓取表格数据并导出到excel文件中
- android 集成RN填坑
- 路由器的两个端口上配置相同的网段
- 圆等分成三个扇形菜单