Done by myself. Aha following step with 867. Transpose Matrix. After I solved it, I found this In-place rotate matrix by 90 degrees in clock-wise direction on web. Interesting. It is likely to be an elegant solution to this problem. “There is no algorithm for creativity.”, as Andy Hargreaves had ever said.
Problem
Java
1
transpose and then swap columns symmetrically
1 | class Solution { |
Submission Detail
- 21 / 21 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Rotate Image.
- Memory Usage: 39.4 MB, less than 5.77% of Java online submissions for Rotate Image.
2
solution of www.geeksforgeeks.org
1 | class Solution { |
Submission Detail
- 21 / 21 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Rotate Image.
- Memory Usage: 39.4 MB, less than 5.77% of Java online submissions for Rotate Image.
non in-place method
matrix rotate
1 | public int[][] rotate_math_stackexchange(int[][] matrix) { |
JavaScript
1 | /** |
Submission Detail
- 21 / 21 test cases passed.
- Runtime: 56 ms, faster than 57.20% of JavaScript online submissions for Rotate Image.
- Memory Usage: 33.4 MB, less than 100.00% of JavaScript online submissions for Rotate Image.