[Leetcode 48, medium] Rotate Image
来源:互联网 发布:国务卿女士 知乎 编辑:程序博客网 时间:2024/05/01 01:27
Problem:
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?
Analysis:
Solutions:
C++:
void SwapClockwise(int &lu, int &lb, int &ru, int &rb) { swap(lu, ru); swap(lb, rb); swap(lu, rb); } void rotate(vector<vector<int> > &matrix) { int n = matrix.size(); if(n <= 1) return; for(int upper = 0, lower = n - 1; upper < lower; ++upper, --lower) { for(int start = upper; start < lower; ++start) { int &lu = matrix[upper][start]; int &ru = matrix[start][lower]; int &lb = matrix[n - 1 - start][upper]; int &rb = matrix[lower][n - 1 - start]; SwapClockwise(lu, lb, ru, rb); } } }Java:
Python:
0 0
- [Leetcode 48, medium] Rotate Image
- LeetCode-48-Rotate Image(模拟)-Medium
- LeetCode 48. Rotate Image (Medium)
- Medium 48题 Rotate Image
- Leetcode 48. Rotate Image (Medium) (cpp)
- Leetcode 48. Rotate Image (Medium) (java)
- Leetcode: 48.Rotate Image(Week4, Medium)
- [leetcode 48] Rotate Image
- [LeetCode 48]Rotate Image
- leetcode || 48、Rotate Image
- leetcode-48 Rotate Image
- Rotate Image - LeetCode 48
- Leetcode 48: Rotate Image
- Leetcode #48 Rotate Image
- LeetCode(48) Rotate Image
- leetcode 48: Rotate Image
- Leetcode#48||Rotate Image
- leetcode 48:Rotate Image
- assert class pointer
- php 实现中文字串截取无乱码的方法
- iOS 相册取图方向不对的问题修复
- php OOP(面向对象)基本理论与知识点
- 高并发Web服务的演变——节约系统内存和CPU
- [Leetcode 48, medium] Rotate Image
- 黑马程序员-iOS视频学习之十一
- [Leetcode] 114. Flatten Binary Tree to Linked List
- bzoj 1709
- 下载文件的Visual Studio工程
- 视频网 市场推广及网站运营实施可行性方案
- android布局中按钮为什么不显示
- Objective-C底层实现
- iOS学习笔记之QuartzCore框架