Python 解leetcode:48. Rotate Image
题目描述:把一个二维数组顺时针旋转90度;
思路:
- 对于数组每一圈进行旋转,使用m控制圈数;
- 每一圈的四个元素顺时针替换,可以直接使用Python的解包,使用k控制每一圈的具体元素;
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
n = len(matrix)
m = 0
while m <= n / 2:
k = m
while k < n - 1 - m:
matrix[m][k], matrix[k][n-1-m], matrix[n-1-m][n-1-k], matrix[n-1-k][m] = \
matrix[n-1-k][m], matrix[m][k], matrix[k][n-1-m], matrix[n-1-m][n-1-k]
k += 1
m += 1
Python 解leetcode:48. Rotate Image的更多相关文章
- [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] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- Python 解LeetCode:Intersection of Two Arrays
最近,在用解决LeetCode问题的时候,做了349: Intersection of Two Arrays这个问题,就是求两个列表的交集.我这种弱鸡,第一种想法是把问题解决,而不是分析复杂度,于是写 ...
- LeetCode 48 Rotate Image(2D图像旋转问题)
题目链接: https://leetcode.com/problems/rotate-image/?tab=Description Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...
- [leetcode 48] rotate image
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
- C#解leetcode 189. Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- Python 解LeetCode:671. Second Minimum Node In a Binary Tree
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
随机推荐
- ECMAScript 5.0 基础语法(下)“稍微重点一点点”
接上篇 七.常用内置对象(复杂数据类型)(重点) (1)数组Array 创建:例 var colors = ['red','blue','green'] #推荐这样,因为简单粗暴 或:v ...
- k8s/Kubernetes常用组件Helm的部署
Helm的安装 1.Helm的基本概念 Helm是Kubernetes的一个包管理工具,用来简化Kubernetes应用的部署和管理.可以把Helm比作CentOS的yum工具. Helm有如下几个基 ...
- JAVA RPC 生产级高可用RPC框架使用分享
先放出链接,喜欢的给个star:https://gitee.com/a1234567891/koalas-rpc 一:项目介绍 koalas-RPC 个人作品,提供大家交流学习,有意见请私信,欢迎拍砖 ...
- java代码连接oracle数据库的方法
oracle连接数据库的方式和mysql是大同小异的,主要的困难点在于oracle的数据库驱动包和依赖只有官方提供,如果你是用maven添加依赖的话,需要自己从官网下载jar包安装到你本地的maven ...
- arcgis python 随机取部分数据
# -*- coding: cp936 -*- import arcpy import os import ylpy import random def main(): num=ylpy.getCou ...
- Git报错: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
在使用Git来克隆仓库报了错误,如下: fatal: unable to access ‘https://github.com/xiaobingchan/machine_learn/‘: OpenSS ...
- Qt编写安防视频监控系统12-异形布局
一.前言 视频监控系统中,除了常规的1画面.4画面.9画面.16画面以外,还有几个布局比较另类,比如6画面.8画面.13画面,有些通道需要占据不同的行列,4画面.9画面.16画面都是非常对称的布局,行 ...
- [译] NAT - 网络地址转换(2016)
[译] NAT - 网络地址转换(2016) Published at 2019-02-17 | Last Update 译者序 本文翻译自 2016 年的一篇英文博客 NAT - Network A ...
- centos下如何关闭xdebug扩展
因为只要加载XDEBUG都会导致系统太慢,所以只有在需要调试系统程序的时候才加载XDEBUG扩展.平时一定要把它给注释掉. 只需要在php.ini文件中注释掉xdebug即可. 即: 前面加一个分号即 ...
- 使用 bash 脚本把 GCE 的数据备份到 GCS
目录 一.Google Cloud Storge 介绍 1.1.四种存储类别的比较 1.2.需求 1.3.给虚拟机添加授权认证 二.备份操作 2.1 创建存储分区 2.2 上传对象到存储分区 2.3 ...