leetcode 将一个二维矩阵进行90度旋转
import numpy as np
import math
if __name__ == '__main__':
def rotate(matrix):
n = len(matrix[0])
for i in range(math.ceil((n-1)/2)):
for j in range(i,n-i-1):
temp = matrix[i][j]
matrix[i][j] = matrix[n-1-j][i]
matrix[n-1-j][i] = matrix[n-1-i][n-1-j]
matrix[n-1-i][n-1-j] = matrix[j][n-1-i]
matrix[j][n-1-i] = temp
return matrix
matrix =np.arange(1,17).reshape(4,4)
print(rotate(matrix))
如图3×3的旋转过程:

如图4×4旋转过程:

leetcode 将一个二维矩阵进行90度旋转的更多相关文章
- python3--算法基础:二维数组转90度
python3--算法基础:二维数组转90度 [0, 1, 2, 3][0, 1, 2, 3][0, 1, 2, 3][0, 1, 2, 3] 二维数组转90度 [0, 0, 0, 0][1, 1, ...
- LeetCode——Rotate Image(二维数组顺时针旋转90度)
问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...
- python-二维数组实现90度旋转
本篇主要介绍了对一个N*N的数组,如果进行90度的旋转 首先,定义一个一维数组很简单,如下: a = [i for i in range(10)] print(a) -----结果----- 0, 1 ...
- LeetCode 搜索二维矩阵 II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- Python算法之动态规划(Dynamic Programming)解析:二维矩阵中的醉汉(魔改版leetcode出界的路径数)
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_168 现在很多互联网企业学聪明了,知道应聘者有目的性的刷Leetcode原题,用来应付算法题面试,所以开始对这些题进行" ...
- [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- [LeetCode] Search a 2D Matrix 搜索一个二维矩阵
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- LeetCode:搜索二维矩阵【74】
LeetCode:搜索二维矩阵[74] 题目描述 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值.该矩阵具有如下特性: 每行中的整数从左到右按升序排列. 每行的第一个整数大于前一行的 ...
- Leetcode之二分法专题-240. 搜索二维矩阵 II(Search a 2D Matrix II)
Leetcode之二分法专题-240. 搜索二维矩阵 II(Search a 2D Matrix II) 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵 ...
随机推荐
- Java&Selenium数据驱动【DataProvider+TestNG+Array】
Java&Selenium数据驱动[DataProvider+TestNG+Array] package testNGWithDataDriven; import java.util.conc ...
- MySQL进阶8 分页查询(limit) - 【SQL查询语法执行顺序及大致结构】- 子查询的3个经典案例
#进阶8 分页查询 /* 应用场景: 当要显示的数据,一页显示不全,需要分页提交sql请求 语法: select 查询列表 #7 from 表1 #执行顺序:#1 [join type join 表2 ...
- Java基础 使用转换流进行文件的复制 / RandomAccessFile 类进行文件的复制
笔记: **使用转换流进行文件的复制 文本文件---字节流FileInputStream--> [InputStreamReader] -----字符流BufferedReader------ ...
- linux实操_shell
简单shell编写: 执行方式: (1)推荐 (2)不推荐
- idea jsp文件中body标签内引入编辑器后提示statement expected
解决方案: 1.用标签将script包一层解决问题 2.或者在</script>后添加自闭和标签(推荐) <input/>.<img/> //等等自闭和标签
- ansible的安装和简单使用
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能.ansible是基于模块工作的,本身没有批量部署的能力.真 ...
- [2019HDU多校第三场][HDU 6603][A. Azshara's deep sea]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6603 题目大意:给出一个凸包,凸包内有若干个圆,要求画尽可能多的对角线使得他们两两不在凸包内相交且不与 ...
- 14、Spring Boot 2.x 集成 Druid 数据源
14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos
- 1、Spring Boot 2.x 简介
GitHub 官方文档 1.1 Spring Boot 是什么? Spring Boot(Boot顾名思义,是引导的意思) 框架是用于简化Spring应用从搭建到开发的过程. 应用开箱即用,只要通过一 ...
- 在多语句事务内不允许使用 CREATE DATABASE 语句。
方法一:create database [ 项目名称] 方法二:update-database -verbose