当前位置:网站首页>1260. 二维网格迁移
1260. 二维网格迁移
2022-07-20 11:44:00 【anieoo】
原题链接:1260. 二维网格迁移
solution:
模拟
class Solution {
public:
vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
int m = grid.size(),n = grid[0].size();
vector<vector<int>> res(m, vector<int> (n, 0));
for(int i = 0;i < m;i++)
for(int j = 0;j < n;j++) {
int x = i, y = j;
y += k;
if(y >= n) {
x += y / n;
y = y % n;
}
if(x >= m) {
x = x % m;
}
res[x][y] = grid[i][j];
}
return res;
}
};
边栏推荐
猜你喜欢
2022 | Sample Efficiency Matters: A Benchmark for Practical Molecular Optimization
深入理解Mysql事务隔离级别与锁机制
Thymeleaf uploads files in web pages
C陷阱和缺陷 第0章 导读
Start to build a three node Eureka cluster
Few-shot Video-to-Video(NeurIPS 2019)视频生成论文解读
Rush's fluid usage (fltk UI Designer)
动手搭建一个三个节点的eureka集群
flinksql读取kafka数据报错
外设篇:ADC
随机推荐
PG运维篇--常用管理命令
谈谈 SAP 产品 UI 开发中的组件概念
你必须知道的4种 Redis 集群方案及优缺点对比
基因组科学数据的安全管理与应用
玩转Makefile文件
获取系统信息
C and pointer Chapter 1 lexical "trap" 1.3 "greedy method" in lexical analysis
Peripherals: nandflash and inand
C和指针 第1章 词法“陷阱” 1.2 &和|不同于&&和||
Yyds dry goods inventory # solve the real problem of famous enterprises: Criminal transfer
MapStruct - Consider defining a bean of type in your configuration.
CV (3)- Loss Functions and Optimization
Start to build a three node Eureka cluster
C陷阱与缺陷 第2章 词法“陷阱” 2.4 switch语句
Postgresql中函数详解看一篇就够了——常用函数以及使用方法
quarkus下的分布式ID怎么实现
C陷阱与缺陷 第2章 语法“陷阱” 2.5 函数调用
C traps and defects Chapter 2 syntax "traps" 2.5 function calls
#yyds干货盘点# 解决名企真题:罪犯转移
如何在Parallels Desktop虚拟机中设置禁止使用第三方插件?