1 Star 0 Fork 0

MetaverseMobile/leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1260_二维网格迁移.cpp 736 Bytes
一键复制 编辑 原始数据 按行查看 历史
TieNan2019 提交于 2021-01-19 18:07 +08:00 . Create 1260_二维网格迁移.cpp
class Solution {
public:
vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
int rows = grid.size();
int cols = grid[0].size();
vector<vector<int>> ans(rows, vector<int>(cols));
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
/* 右移 */
int c = (col + k) % cols;
/* 下沉 */
int r = (row + (col + k) / cols) % rows;
ans[r][c] = grid[row][col];
}
}
return ans;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/MetaverseMobile/leetcode.git
git@gitee.com:MetaverseMobile/leetcode.git
MetaverseMobile
leetcode
leetcode
main

搜索帮助

371d5123 14472233 46e8bd33 14472233