GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Algorithm/java/coding/rotateImage.java at master · lelea2/Algorithm Expand file tree/ Copy pathrotateImage.javaMore file actions 20 lines (19 loc) · 653 Bytes / Copy pathrotateImage.javaFile metadata and controls20 lines (19 loc) · 653 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /** * You are given an n x n 2D matrix representing an image. *Rotate the image by 90 degrees (clockwise). */ //Idead //By using the relation "matrix[i][j] = matrix[n-1-j][i]", we can loop through the matrix. //Use temp to set matrix[i][j] public void rotate(int[][] matrix) { int n = matrix.length; for (int i = 0; i < n / 2; i++) { for (int j = 0; j < Math.ceil(((double) n) / 2); j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[n-1-j][i]; matrix[n-1-j][i] = matrix[n-1-i][n-1-j]; matrix[n-1-i][n-1-j] = matrix[j][n-1-i]; matrix[j][n-1-i] = temp; } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |