10000 edit 48 · seshireddy/Leetcode@507ca82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 507ca82

Browse files
edit 48
1 parent 4cc2604 commit 507ca82

File tree

1 file changed

+3
-5
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-5
lines changed

src/main/java/com/fishercoder/solutions/_48.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
*/
1313
public class _48 {
1414

15-
//credit: https://discuss.leetcode.com/topic/9744/ac-java-in-place-solution-with-explanation-easy-to-understand
1615
public void rotate_O1(int[][] matrix) {
1716
/**First swap the elements on the diagonal, then reverse each row:
1817
* 1, 2, 3 1, 4, 7 7, 4, 1
1918
* 4, 5, 6 becomes 2, 5, 8 becomes 8, 5, 2
2019
* 7, 8, 9 3, 6, 9 9, 6, 3
21-
This could be done in O(1) space!
20+
This is done in O(1) space!
2221
**/
2322
int m = matrix.length;
2423
int n = matrix[0].length;
2524
for (int i = 0; i < m; i++) {
26-
for (int j = i; j < n; j++) {
25+
for (int j = i; j < n; j++) {/**ATTN: j starts from i, so that the diagonal changes with itself, no change.*/
2726
int tmp = matrix[i][j];
2827
matrix[i][j] = matrix[j][i];
2928
matrix[j][i] = tmp;
@@ -39,13 +38,12 @@ This could be done in O(1) space!
3938
}
4039
}
4140

42-
//credit: https://discuss.leetcode.com/topic/6796/a-common-method-to-rotate-the-image
4341
/**First swap the rows bottom up, then swap the element on the diagonal:
4442
* 1, 2, 3 7, 8, 9 7, 4, 1
4543
* 4, 5, 6 becomes 4, 5, 6 becomes 8, 5, 2
4644
* 7, 8, 9 1, 2, 3 9, 6, 3
4745
* */
48-
//however, this is using O(n) of extra space
46+
/**This is using O(n) of extra space*/
4947
public void rotate_On(int[][] matrix) {
5048
int m = matrix.length;
5149
int n = matrix[0].length;

0 commit comments

Comments
 (0)
0