Description:
As we read the description of problem, we can't make another matrix for output.
That means we can change the image without making matrix.
Solution:
We set left+=1 and right-=1, but it is out of for loop!, so that means we should change the left and top in person. The "i" means that how much apart from the beginning or the end of matrix.
In example 1, after we change the value by the first time, then second time would be change the values 2, 6, 8, 4 which is diagonal form.
2 is apart i(=1) from the left.
4 is apart i from bottom.
6 is appart i from top.
8 is appart i from right.
Time Complexity: O(N^2)
Space Complexity: O(1)
'LeetCode ๐๏ธ > Matrix' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
79. Word Search (0) | 2023.02.13 |
---|---|
54. Spiral Matrix (0) | 2023.02.05 |
73. Set Matrix Zeroes (0) | 2023.02.02 |