leetcode-easy-array-48. Rotate Image-NO
mycode
思路:第m行要变到 - 1- m 列 ,但是没有再想一步即列变为行,这样每一个位置的变换方式就出来了
难点:如何不使用额外空间呢?
参考:
思路:找到矩阵旋转和转置之间的联系,转置是可以原地运算的
class Solution:
def rotate(self, matrix):
"""
Do not return anything, modify matrix in-place instead.
"""
k=len(matrix)
for i in range(k):
for j in range(i+1,k):
matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j]
for i in range(k):
matrix[i]=matrix[i][::-1]
leetcode-easy-array-48. Rotate Image-NO的更多相关文章
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- [Leetcode][Python]48: Rotate Image
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 48: Rotate Imagehttps://leetcode.com/pr ...
- 48. Rotate Image - LeetCode
Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...
- 【LeetCode】Array
[11] Container With Most Water [Medium] O(n^2)的暴力解法直接TLE. 正确的解法是Two Pointers. O(n)的复杂度.保持两个指针i,j:分别指 ...
- Leetcode easy
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- 刷题48. Rotate Image
一.题目说明 题目是48. Rotate Image,简而言之就是矩阵顺时针旋转90度.不允许使用额外的矩阵. 经过观察(写一个矩阵,多看几遍就知道了),旋转90度后: 第1行变为len-1列(最后一 ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- <LeetCode OJ> 189. Rotate Array
189. Rotate Array Total Accepted: 55073 Total Submissions: 278176 Difficulty: Easy Rotate an array o ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 189. 旋转数组(Rotate Array)
189. 旋转数组 LeetCode189. Rotate Array 题目描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: [1,2,3,4,5,6, ...
随机推荐
- mysql数据库常见错误代码列表
mysql出错代码列表1005:创建表失败 1006:创建数据库失败 1007:数据库已存在,创建数据库失败 1008:数据库不存在,删除数据库失败 1009:不能删除数据库文件导致删除数据库失败 1 ...
- luogu P3210 [HNOI2010]取石头游戏
传送门 不会结论做个鬼系列 题意其实是在头尾(最多)两个栈以及中间一些双端队列依次取数,然后每个人都要最大化自己的价值 有一个结论,如果一段序列中,出现了三个相邻位置\(A,B,C\),满足\(A\l ...
- jsp+servlet实现文件上传下载
相关素材下载 01.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- 2019-11-29-VisualStudio-2019-尝试使用-C#-8.0-新的方式
title author date CreateTime categories VisualStudio 2019 尝试使用 C# 8.0 新的方式 lindexi 2019-11-29 08:41: ...
- [转载]一个支持Verilog的Vim插件——AutoDef
原文地址:一个支持Verilog的Vim插件--AutoDef作者:hover 支持一下四种类型的变量声明: 1)时序always块中的寄存器变量reg 2)组合always块中的组合reg变量reg ...
- Oracle 之 触发器
触发器是特定的事件出现的时候,自动隐式执行代码块,这个过程用户无法控制,用户只能控制触发的事件,触发后的操作,触发过程是自动执行的. 定义触发器: 1.名称 2.触发时间:是在执行事件之前(befor ...
- 【转载】网易极客战记官方攻略-地牢-Kithgard 橱柜 A
关卡连接: https://codecombat.163.com/play/level/cupboards-of-kithgard-a 谁知道什么样的恐怖事情潜伏在 Kithgard 的橱柜里? 简介 ...
- u-boot log_init函数分析
log_init, int log_init(void){ struct log_driver *drv = ll_entry_start(struct log_driver, log_driv ...
- bootstrap-table(2)问题集
参考;https://www.cnblogs.com/landeanfen/p/4993979.html 1.分页参数sidePagination 如果是服务端分页,返回的结果必须包含total.ro ...
- while循环练习:
输入姑娘的年龄后,进行以下判断: 如果姑娘小于18岁,打印"不接受未成年" 如果姑娘大于18岁小于25岁,打印"心动表白" 如果姑娘大于25岁小于45岁,打印& ...