Leetcode Rotate Image
2016-07-20 03:34
483 查看
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?
Difficulty: Medium
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
Difficulty: Medium
public class Solution { public void helper(int[][] matrix, int i, int j){ int pre = matrix[i][j]; for(int k = 0; k < 4; k++){ int temp = matrix[j][matrix.length - 1- i]; matrix[j][matrix.length - 1- i] = pre; pre = temp; temp = i; i = j; j = matrix.length - 1 - temp; } } public void rotate(int[][] matrix) { int n = matrix.length, mid = n/2 - 1; for(int i = 0; i <= mid + n%2; i++){ for(int j = 0; j <= mid; j++){ helper(matrix, i, j); } } return; } }
相关文章推荐
- 最小边割集
- 云服务器上安装配置Filezilla Server的坑!
- 在安装Ubuntu的MacBook上更改Apple 键盘模式
- 算法日记(Java实现)第20160719(5)期——POJ1008
- 在MacBook Pro 12-1 with ubuntu 15.10 上安装风扇控制器(mbpfan)
- HDU5723 2016 Multi-University Training Contest 1 (最小生成树+dfs)
- 百度地图API 地理位置获取和大头针显示当前位置
- KVM的网络Networking-qemu-kvm和openvswitch原型环境部署和基本测试 (3)
- 创建虚拟机-qemu-kvm和openvswitch原型环境部署和基本测试 (2)
- 基于栈数据结构的算法(poj-布尔表达式)
- git push 提示输入用户名和密码
- qemu-kvm和openvswitch安装部署-qemu-kvm和openvswitch原型环境部署和基本测试 (1)
- Leetcode 33, 81 Search in Rotated Sorted Array I, II
- Android短信发送,监听,及其工具类封装
- HDU 5727 Necklace(玄学+状压DP 或 匈牙利)
- 基本标签
- js window.onload ,$(function(){}) 和script标签 运行规则和错误引起下面的js不能运行 探讨
- as3 中 textfiled的htmltext 的常用属性
- windows下,python的各类包的安装(cython, numpy, xlrd, xlwt)
- 搬家成功!