Created
January 17, 2020 15:44
-
-
Save anirudhjain75/0618e1e5c78f87be779355f65ddf8416 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("Rotate Leetcode 58") | |
a := [][]int{{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}} | |
rotate(a) | |
} | |
func reverse(numbers []int) []int { | |
for i := 0; i < len(numbers)/2; i++ { | |
j := len(numbers) - i - 1 | |
numbers[i], numbers[j] = numbers[j], numbers[i] | |
} | |
return numbers | |
} | |
func rotate(matrix [][]int) { | |
// Rotate outer part of matrix | |
for j:=0;j<1;j++{ | |
temp := make([]int, len(matrix) - 2*j) | |
n := len(matrix) - 1 | |
for i, v := range matrix[0] { | |
temp[i] = v | |
} | |
for i:=0;i<n;i++ { | |
matrix[0+j][i] = matrix[n - i][0 + j] | |
matrix[n-i][0+j] = matrix[n - j][n - i] | |
matrix[n-j][n-i] = matrix[i][n - j] | |
matrix[i][n-j] = temp[i] | |
} | |
} | |
//Print the 2D matrix for verification | |
for _, v := range matrix { | |
for _, val := range v { | |
fmt.Print(val, " ") | |
} | |
fmt.Println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment