Leetcode 566 Reshape the Matrix
来源:互联网 发布:斯诺登现状2017 知乎 编辑:程序博客网 时间:2024/06/06 01:39
Leetcode 566 Reshape the Matrix
#include <vector>using namespace std;class Solution {public: vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) { if(nums.empty()) return nums; int rsize = nums.size(); int csize = nums[0].size(); if(rsize * csize != r * c) return nums; vector<vector<int>> result(r,vector<int>(c)); for(int i = 0;i < rsize;i ++) { for(int j = 0;j < csize; j++) { int number = i * csize + j;//第几个数 int newi = number / c; int newj = number % c; result[newi][newj] = nums[i][j]; } } return result; }};
阅读全文
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
- Reshape the Matrix(leetcode)
- leetCode-Reshape the Matrix
- Array-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之Reshape the Matrix
- LeetCode:566. Reshape the Matrix
- leetcode 566. Reshape the Matrix
- LeetCode | 566. Reshape the Matrix
- leetcode-566. Reshape the Matrix
- Linux利用crontab创建计划任务详解
- 使用struts2框架遇到的问题
- jsp+servlet验证码验证
- Leetcode 53 Maximum Subarray
- Maximum Subarray
- Leetcode 566 Reshape the Matrix
- LeetCode 0683
- install phantomjs 2.1.1
- “程序媛计划”--女孩们的魔法棒
- Evaluate Division
- Leetcode 70 Climbing Stairs
- linux fb /lcd 驱动
- JAVA中的反射机制
- 数据库事务4种隔离级别详解