leetcode 旋转图像

 2023-09-06 阅读 17 评论 0

摘要:21 / 21 个通过测试用例状态:通过执行用时:0 ms内存消耗:36.2 MB提交时间:6 月,3 周之前class Solution {//本代码 来自[emailprotected]杨晓慧-Hepburnpublic void rotate(int[][] matrix) {int abs1 = 0;int abs2 = matrix.len

21 / 21 个通过测试用例
状态:通过
执行用时:0 ms
内存消耗:36.2 MB
提交时间:6 月,3 周之前

class Solution {//本代码 来自[email protected]杨晓慧-Hepburnpublic void rotate(int[][] matrix) {int abs1 = 0;int abs2 = matrix.length - 1;int times = 0;while (abs1 <= abs2) {int p1 = abs1;int p2 = abs2;while (p1 != abs2) {// 转换的思路:// 1.先保存左上的值到临时变量// 2.左下--> 左上, 右下-->左上, 右上-->右下,临时变量内的左上-->右上int temp = matrix[abs1][p1];         //左上matrix[abs1][p1] = matrix[p2][abs1]; //左上 = 左下matrix[p2][abs1] = matrix[abs2][p2]; //左下 = 右下matrix[abs2][p2] = matrix[p1][abs2]; //右下 = 右上matrix[p1][abs2] = temp;             //右上 = 左上p1 += 1;p2 -= 1;}abs1 += 1;abs2 -= 1;}}
}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/5260.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息