[LeetCode] Rotate Image
2014-04-09 18:03
232 查看
Total Accepted: 7942 Total Submissions: 26120
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?
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?
public class Solution { public void rotate(int[][] matrix) { int n = matrix[0].length; for (int i = 0; i < n/2; i++) { for (int j = i; j < n-1-i; j++) { int 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; } } } }
相关文章推荐
- LeetCode刷题【Array】 Rotate Image
- 48. Rotate Image Leetcode Python
- leetcode 日经贴,Cpp code -Rotate Image
- LeetCode_rotate-image
- Leetcode | Rotate Image
- LeetCode_Rotate Image
- [Leetcode 66] 48 Rotate Image
- Leetcode刷题记——48. Rotate Image(旋转图像)
- Leetcode: 48.Rotate Image(Week4, Medium)
- LeetCode:Rotate Image
- 33_leetcode_Rotate Image
- LeetCode048 Rotate Image
- [leetcode] Rotate Image
- LeetCode 48 Rotate Image
- LeetCode 48. Rotate Image (Medium)
- LeetCode - 48. Rotate Image
- LeetCode之Rotate Image
- leetcode之Rotate Image
- LeetCode 48. Rotate Image(旋转)
- Leetcode-48. Rotate Image