-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/diguage/algo/leetcode/_0048_RotateImage_2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.diguage.algo.leetcode; | ||
|
||
public class _0048_RotateImage_2 { | ||
// tag::answer[] | ||
|
||
/** | ||
* @author D瓜哥 · https://www.diguage.com | ||
* @since 2024-09-19 17:35:53 | ||
*/ | ||
public void rotate(int[][] matrix) { | ||
backtrack(matrix, 0, 0, | ||
matrix.length, matrix.length); | ||
} | ||
|
||
private void backtrack(int[][] matrix, | ||
int row, int column, | ||
int rLen, int cLen) { | ||
if (rLen <= 1) { | ||
return; | ||
} | ||
// 旋转 | ||
for (int i = 0; i < cLen - 1; i++) { | ||
int tmp = matrix[row][column + i]; | ||
matrix[row][column + i] = matrix[row + rLen - 1 - i][column]; | ||
matrix[row + rLen - 1 - i][column] = matrix[row + rLen - 1][column + cLen - 1 - i]; | ||
matrix[row + rLen - 1][column + cLen - 1 - i] = matrix[row + i][column + cLen - 1]; | ||
matrix[row + i][column + cLen - 1] = tmp; | ||
} | ||
backtrack(matrix, row + 1, column + 1, rLen - 2, cLen - 2); | ||
} | ||
// end::answer[] | ||
} |