像素翻转
来源:互联网 发布:mac qq截图失效 编辑:程序博客网 时间:2024/05/13 17:34
题目描述
有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。
给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转后的NxN矩阵,保证N小于等于500,图像元素小于等于256。
测试样例:
[[1,2,3],[4,5,6],[7,8,9]],3
返回:[[7,4,1],[8,5,2],[9,6,3]]
import java.util.*;public class Transform { public int[][] transformImage(int[][] mat, int n) { // write code here for(int layer=0; layer<n/2; ++layer){ int first = layer; int last = n-1-layer; for(int i=first; i<last; ++i){ int offset = i - first; int top = mat[first][i]; mat[first][i] = mat[last-offset][first]; mat[last-offset][first] = mat[last][last-offset]; mat[last][last-offset] = mat[i][last]; mat[i][last] = top; } } return mat; }}
0 0
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 像素翻转
- 图片像素翻转。水平翻转,垂直翻转。
- 像素翻转(Java)
- 牛客网 | 像素翻转
- 第四天 像素翻转
- 《剑指offer》像素翻转
- 像素翻转Java实现
- Yii2的异步多线程服务之swoole
- xfire+spring+ibatis(详细)
- leetcode_122 Best Time to Buy and Sell Stock II
- Android中的适配器模式
- 【重要】ViewPager的主意事项
- 像素翻转
- 多线程结合案例详解
- 设置内存使用率而启用swap的参数
- Android性能优化之一 布局优化
- Landoj 1603 - Minimum Sum (暴力&模拟)
- IntelliJ Idea 常用快捷键列表
- HDU_1754_I Hate It
- SqlServer ETL 数据抽取工具SSIS之环境搭建
- AutoCompleteTextView:自动提示