当前位置:网站首页>[daily question] 1260 2D mesh migration
[daily question] 1260 2D mesh migration
2022-07-21 07:58:00 【lyz_ fish】
Master link :https://leetcode.cn/problems/shift-2d-grid/
class Solution:
def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]:
def convert_horizon(grid):
temp = 0
m = len(grid)
n = len(grid[0])
one_change = list()
for nums in grid:
temp = nums[-1]
nums[1:n] = nums[:n-1]
nums = deque(nums)
nums.popleft()
nums.appendleft(temp)
one_change.append(list(nums))
return one_change
def convert_vertical(list_):
list_copy = list_
for index,value in enumerate(convert_horizon([[i[0] for i in list_copy]])[0]):
list_[index][0] = value
return list_
ans = grid
for _ in range(k):
ans = convert_horizon(ans)
ans = convert_vertical(ans)
return ans
author :li-ze-yu-o4
link :https://leetcode.cn/problems/shift-2d-grid/solution/by-li-ze-yu-o4-phca/
source : Power button (LeetCode) The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- You might as well give more guidance to "cloud interview"
- Ultra light fast generic face detector 1MB custom dataset training | multi classification modification Guide (1)
- Hcip notes day 8
- Unity学习笔记 之 发射小球碰撞物体的代码记录
- VPS、独服和云服务器哪种最适合您的业务?
- 面试真题2
- Uiscrollview and uipagecontrol realize startup sliding diagram [easy to understand]
- 【机器学习】《蒲公英书》1
- 没有投机stock的命,该放弃的就明智果断放弃才是上策
- 初识MySQL
猜你喜欢
随机推荐
1260. 二维网格迁移 : 简单构造模拟题
[redis] summary of common knowledge points
IReport导出PDF字体加粗失效
2022/7/18-7/19
Redis Learning notes (1) - Power Node of Station B
Will ABAP really become obsolete? Talk about the past, present and future of ABAP
FC can the background script be run all the time? For example, keep going to the database to get data processing and write it to another database
【安全公告】Apache Spark shell 命令注入漏洞(CVE-2022-33891)风险通告
初识MySQL
2020 Huawei cloud community annual technology collection, 700 pages + free download| Yunxiang library No.01 recommendation (with free download)
Insightface paddle User Guide (2)
OCR/STR生僻字数据训练 | PaddleOCR的Fine-tune常见问题汇总(3)
ArcGIS Api For Flex 动态画点和线
精品方案|海泰云密码应用服务解决方案 打造安全合规的云上应用
OSPF comprehensive experiment
[IOT] Product Manager: the underlying logic of human insight
R语言Kolmogorov-Smirnov检验比较两个样本是否来自同一个分布:ks.test函数执行Kolmogorov-Smirnov检验比较两个样本是否来自同一个分布
how to deal with " no such file error or diretory" error for a new programmer in QT creator
Audio and video learning (VIII) -- RTP protocol
VIM encrypted file "recommended collection"