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, ...
随机推荐
- Linux中如何添加/删除FTP用户并设置权限
在linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被设置用户名为test.被限制路径为/home/test 2.创建建用户:在root用户下: user ...
- 84. Largest Rectangle in Histogram (JAVA)
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Linux往log中写日志
void writelog(const char* log) { time_t tDate; struct tm* eventTime; time(&tDate);//得到系统当前时间 //将 ...
- 树莓派3b+下一些常用的命令(Debian下)
安装Mysqlsudo apt-get install mysql-server即可 注:第一次登陆是可能出现以下错误,则按顺序输入命令即可: ERROR 1698 (28000):Access de ...
- Coco56公众号关键字索引
目录 1. 本文地址 2. 公众号介绍 3. 关键词及含义 1. 本文地址 博客园:https://www.cnblogs.com/coco56/p/11182421.html 简书:https:// ...
- 查看 php 编译参数
/app/php/bin/php -i|grep configure 范例 4: [root@VM-001 ~]# /app/php/bin/php -i|grep configure Configu ...
- install-info - 更新 info/dir 项
SYNOPSIS 总览 install-info [OPTION]... [INFO-FILE [DIR-FILE]] DESCRIPTION 描述 从 Info 目录文件 DIR-FILE 中的文件 ...
- html-DOM了解
什么是 HTML DOM? HTML DOM 是: HTML 的标准对象模型 HTML 的标准编程接口 W3C 标准 HTML DOM 定义了所有 HTML 元素的对象和属性,以及访问它们的方法. 换 ...
- 2019.9.16:java课后测验
一.动手动脑 1. 枚举类型是引用类型, 枚举不属于原始数据类型,它的每个具体值都引用一个特定的对象.相同的值则引用同一个对象. 可以使用“==”和equals()方法直接比对枚举变量的值,换句话说, ...
- Java基本的程序结构设计 整形和浮点型
整形: int 4字节 short 2字节 long 8字节 byte 1字节 int的大小差不多是20亿. 整形计算 如果两个int进行加减乘除数学运算的时候,最终的结果仍然是int,有可能出现了溢 ...