Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbaek7023/662648adc69890ea6ad546fbe5ca9139 to your computer and use it in GitHub Desktop.
Save jbaek7023/662648adc69890ea6ad546fbe5ca9139 to your computer and use it in GitHub Desktop.
My solution (not working) - Rotate Image.
class Solution:
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
# S: Ceil Py without math
for level in range(len(matrix)//2):
# 4-> 2, 5 -> 2.
# SEarched floor
for index in range(level, len(matrix)-1-level):
# [0, 1, 2, 3, 4] -> [1, 2, 3] -> [2]
# [0, 1, 2, 3] -> [1, 2]
# lt, lb, rb, rt
temp = matrix[level][index+level]
# lt = lb ###
matrix[level][index + level] = matrix[len(matrix)-1-index-level][level]
# lb = rb ####
matrix[len(matrix)-1-index-level][level] = matrix[len(matrix)-1-level][len(matrix)-1-index-level]
# rb = rt
matrix[len(matrix)-1-level][len(matrix)-1-index-level] = matrix[index+level][len(matrix)-1-level]
# rt = lt
matrix[index+level][len(matrix)-1-level] = temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment