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, ...
随机推荐
- CNN与图像应用
一.图像识别与定位 0.Classification:C个类别 Input:Image Output:类别标签 Evaluation metric:准确率 1.Localization: Input: ...
- SVM支持向量机(1)
一.SVM模型 1.函数间隔与几何间隔,哪一条线是最好的? (1)公式化问题. 分类模型:当里面的值小于0的时候就是-1,当里面的值是大于等于0的时候就是1 函数间隔:前面乘以y(i),是为了保持数值 ...
- 2019-11-29-Roslyn-打包自定义的文件到-NuGet-包
title author date CreateTime categories Roslyn 打包自定义的文件到 NuGet 包 lindexi 2019-11-29 08:23:21 +0800 2 ...
- laravel查询数据库获取结果如何判断是否为空?
laravel 查询数据库获取结果如何判断是否为空? 大家使用的场景是这样的: 1 $users = DB::table('users')->where('id',$id)->get(); ...
- SpringBootMVC02——Spring Data JPA的使用&JSP的使用
Spring Data JPA的使用 实体层 package com.littlepage.domain; import javax.persistence.Entity; import javax. ...
- 详解PHP文件下载的原理和实现
通常文件下载过程是十分简单的,建立一个链接指向到目标文件就可以了.例如下面的链接: XML/HTML代码 <a href=http://www.xxx.com/xxx.rar>点击下载文件 ...
- git常用的操作命令
设置git用户名/邮箱: $ git config user.name 'github用户名' $ git config user.email '邮箱' 从指定分支切换新分支: git checkou ...
- ASP.NET 中 取得 Repeater 里的checkbox值
前言:这两天在维护ASP.NET的项目,需要做一个checkbox来选择数据进行导出,下面提供两种解决思路 1.ASP:CheckBox asp:CheckBox自带控件,没有Value值 <a ...
- python爬虫及结巴分词《攀登者》影评分析
<攀登者>影评爬取及分析 0.项目结构 其中simkai.ttf为字体文件,Windows查看系统自带的字体 C:\Windows\Fonts 一.爬取豆瓣影评数据 # -*- codin ...
- Vue的css动画原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...