48. Rotate Image - LeetCode
Question
Solution
把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转
public void rotate(int[][] matrix) {
int n = matrix.length;
for (int i = 0; i < n / 2; i++) {
change(matrix, i);
}
}
private void change(int[][] matrix, int i) {
int n = matrix.length - 1;
for (int j = i; j < n - i; j++) {
int tmp = matrix[i][j];
matrix[i][j] = matrix[n - j][i];
matrix[n - j][i] = matrix[n - i][n - j];
matrix[n - i][n - j] = matrix[j][n - i];
matrix[j][n - i] = tmp;
}
}
48. Rotate Image - LeetCode的更多相关文章
- [Leetcode][Python]48: Rotate Image
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 48: Rotate Imagehttps://leetcode.com/pr ...
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- 刷题48. Rotate Image
一.题目说明 题目是48. Rotate Image,简而言之就是矩阵顺时针旋转90度.不允许使用额外的矩阵. 经过观察(写一个矩阵,多看几遍就知道了),旋转90度后: 第1行变为len-1列(最后一 ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- 【一天一道LeetCode】#48. Rotate Image
一天一道LeetCode系列 (一)题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 ...
- LeetCode 48 Rotate Image(2D图像旋转问题)
题目链接: https://leetcode.com/problems/rotate-image/?tab=Description Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...
- 【LeetCode】48. Rotate Image
Difficulty:medium More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/rotate-image/ ...
- 【LeetCode】48. Rotate Image 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- 攻防世界 Ditf misc
Ditf 附件下载下来就是一张图片,我们拉到hxd中发现应该有隐藏的压缩包 我们拉入到kali里面分析 意外发现图片高度被修改过我们先用binwalk分析图片看看 我们先尝试分离一下分离出一个压缩包但 ...
- apollo规划控制视频-12basic motion planning and overview
- 切图崽的自我修养-[ES6] 迭代器Iterator浅析
Iterator 这真是毅种循环 Iterator不是array,也不是set,不是map, 它不是一个实体,而是一种访问机制,是一个用来访问某个对象的接口规范,为各种不同的数据结构提供统一的访问机制 ...
- 前端调试利器 - Charles
Docs 开发之 Charles 配置指南 1.下载与安装 charles-proxy-4.1.4 .dmg56.12 MB已存到云盘下载 2.激活 使用公司正版license 激活 安装证书 点击证 ...
- sql server学习总结一
一,数据库的三级模式结构 1. 模式 模式又称逻辑模式或者概念模式,是数据库中全体数据的逻辑结构和特征的描述,一个数据库只有一个模式,模式处于三级结构的中间层. 2. 外模式 外模式又称用 ...
- 实现一个promise.all方法
思路: 1:首先明白all的用法 2:promise.all可以接受一个由promise数组作为参数,并且返回一个promise实例, 3:promise.all([a,b,c...]).then方法 ...
- Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found 解决办法
问题 每次vs重启都提示安装证书,即使执行dotnet dev-certs https --clean,dotnet dev-certs https -t然后重启vs也不行. 环境 win10, vs ...
- 实现WebMvcConfigurer接口扩展Spring MVC的功能
前言: 先查看WebMvcConfigurer接口中都定义了哪些内容 public interface WebMvcConfigurer { default void configurePathMat ...
- 7.Docker容器使用辅助工具汇总
原文地址: 点击直达 more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack- ...
- 学习day43
开始学习html知识