Skip to content

Commit fe439ec

Browse files
authored
rotate image solution
1 parent bd3c898 commit fe439ec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rotate-image/yhkee0404.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func rotate(matrix [][]int) {
2+
for i := range len(matrix) {
3+
for j := i + 1; j != len(matrix[i]); j++ { // T(n) = O(n)
4+
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
5+
}
6+
}
7+
for _, row := range matrix {
8+
for i, j := 0, len(row) - 1; i < j; {
9+
row[i], row[j] = row[j], row[i]
10+
i++
11+
j--
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)