[leetcode]Rotate Image @ Python
原题地址:https://oj.leetcode.com/problems/rotate-image/
题意:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
解题思路:先将矩阵转置,然后将矩阵的每一行翻转,就可以得到所要求的矩阵了。
代码:
class Solution:
# @param matrix, a list of lists of integers
# @return a list of lists of integers
def rotate(self, matrix):
n = len(matrix)
for i in range(n):
for j in range(i+1, n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for i in range(n):
matrix[i].reverse()
return matrix
[leetcode]Rotate Image @ Python的更多相关文章
- [leetcode]Rotate List @ Python
原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...
- C++ STL@ list 应用 (leetcode: Rotate Array)
STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...
- [LeetCode]题解(python):061-Rotate list
题目来源 https://leetcode.com/problems/rotate-list/ Given a list, rotate the list to the right by k plac ...
- [LeetCode]题解(python):048-Rotate Image
题目来源 https://leetcode.com/problems/rotate-image/ You are given an n x n 2D matrix representing an im ...
- [LeetCode] 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] Rotate List 旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- [LeetCode] Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [LeetCode]题解(python):120 Triangle
题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...
随机推荐
- 子域名枚举工具Sublist3r
子域名枚举工具Sublist3r 通过搜集子域名信息,可以找到目标的关联网站,找寻相应的漏洞.Kali Linux提供一款基于OSINT的枚举工具Sublist3r.该工具会搜索多个数据来源,如G ...
- Xamarin iOS教程之进度条和滚动视图
Xamarin iOS教程之进度条和滚动视图 Xamarin iOS 进度条 进度条可以看到每一项任务现在的状态.例如在下载的应用程序中有进度条,用户可以很方便的看到当前程序下载了多少,还剩下多少.Q ...
- Web大前端面试题-Day1
1. var的变量提升的底层原理是什么? JS引擎的工作方式是:1) 先解析代码,获取所有被声明的变量:2)然后在运行.也就是说分为预处理和执行两个阶段. 变量提升:所有变量的声明语句都会被提升到代码 ...
- android 上下边框线
<!-- 连框颜色值 --> <item> <shape> <solid android:color="@android:color/backgro ...
- android 的安全问题
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 1,webView的js脚本引发的安全 2,代码的混淆加密.还可采用第三方apk加固程序 ...
- CS1.6找金钱和人物血量
一.查找金钱数量 先搜索800 然后购买东西,再搜索剩下的钱 然后发现有两个地址,一个绿色的地址(也就是静态地址),还有一个动态地址 经过测试后,静态地址的值是对应屏幕上的值,而真正实际的金钱是那个动 ...
- BZOJ4255 : Keep Fit!
首先旋转坐标系,把每个点可以接收的范围转化成一个正方形. 然后建立k-d tree,并记录下每个点在k-d tree上的位置. 对询问使用莫队算法,修改$O(\log n)$,查询期望$O(\log ...
- 使用36-pin的STM32输出VGA, VGA output using a 36-pin STM32
使用36-pin的STM32输出VGA 手头上有个项目需要通过单片机来控制将图像显示在LCD上,在网上搜了一阵子,发现都是使用的FPGA做的, 开始自己对FPGA不是很熟,一直在用的也是ARM系列的, ...
- AES CBC/CTR 加解密原理
So, lets look at how CBC works first. The following picture shows the encryption when using CBC (in ...
- lufylegend:图形变形3
面来看看drawtriangles函数的扩展.利用drawtriangles函数来实现一个旋转的3D地球,效果如下 因为lufylegend1.5.0版的drawtriangles函数有个bug,所以 ...