[LeetCode] Rotate Image

简介: A simple and in-place idea: first reverse the image in row-major order and then transpose it :-) 1 class Solution { 2 public: 3 void rotat...

A simple and in-place idea: first reverse the image in row-major order and then transpose it :-)

 1 class Solution {
 2 public:
 3     void rotate(vector<vector<int>>& matrix) {
 4         reverse(begin(matrix), end(matrix));
 5         int m = matrix.size(), n = matrix[0].size();
 6         for (int i = 0; i < m; i++)
 7             for (int j = 0; j < i; j++)
 8                 swap(matrix[i][j], matrix[j][i]);
 9     }
10 };

 

目录
相关文章
LeetCode 189. 旋转数组 Rotate Array
LeetCode 189. 旋转数组 Rotate Array
LeetCode 189. Rotate Array
给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
52 0
LeetCode 189. Rotate Array
|
索引
LeetCode 61. Rotate List
给定链表,将列表向右旋转k个位置,其中k为非负数。
60 0
LeetCode 61. Rotate List
LeetCode 48. Rotate Image
给定一个n x n的二维矩阵,以顺时针方向旋转90度
56 0
LeetCode 48. Rotate Image
|
机器学习/深度学习 存储 人工智能
LeetCode 832. Flipping an Image
LeetCode 832. Flipping an Image
80 0
|
Python
Leetcode-Easy 796. Rotate String
Leetcode-Easy 796. Rotate String
53 0
Leetcode-Easy 796. Rotate String
LeetCode之Rotate Array
LeetCode之Rotate Array
102 0
LeetCode 61:旋转链表 Rotate List
​给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。 Given a linked list, rotate the list to the right by k places, where k is non-negative.
3071 0
|
算法 Java 索引
LeetCode 189:旋转数组 Rotate Array
公众号:爱写bug(ID:icodebugs) 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 Given an array, rotate the array to the right by k steps, where k is non-negative.
741 0
|
C++
LeetCode 189 Rotate Array(旋转数组)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/50600861 翻译 通过K步将一个有着n个元素的数组旋转到右侧。
756 0