<reponame>NursultanBeken/leetcode_practice<filename>blind_75/12_rotate_img.py
"""
https://www.youtube.com/watch?v=fMSJSS7eO1w
"""

class Solution(object):
    def rotate(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: None Do not return anything, modify matrix in-place instead.
        """
        l, r = 0, len(matrix) - 1
        
        while l<r:
            for i in range(r-l):
                top, bottom = l, r
                
                #save top left
                top_left = matrix[top][l+i]
                
                #move bottom left
                matrix[top][l+i] = matrix[bottom-i][l]
                
                #move bottom right
                matrix[bottom-i][l] = matrix[bottom][r-i]
                
                #move top right
                matrix[bottom][r-i] = matrix[top+i][r]
                
                #move top left
                matrix[top+i][r] = top_left
            
            l +=1
            r -=1
"""
https://www.youtube.com/watch?v=fMSJSS7eO1w
"""

class Solution(object):
    def rotate(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: None Do not return anything, modify matrix in-place instead.
        """
        l, r = 0, len(matrix) - 1
        
        while l<r:
            for i in range(r-l):
                top, bottom = l, r
                
                #save top left
                top_left = matrix[top][l+i]
                
                #move bottom left
                matrix[top][l+i] = matrix[bottom-i][l]
                
                #move bottom right
                matrix[bottom-i][l] = matrix[bottom][r-i]
                
                #move top right
                matrix[bottom][r-i] = matrix[top+i][r]
                
                #move top left
                matrix[top+i][r] = top_left
            
            l +=1
            r -=1
https://www.youtube.com/watch?v=fMSJSS7eO1w :type matrix: List[List[int]]         :rtype: None Do not return anything, modify matrix in-place instead. #save top left #move bottom left #move bottom right #move top right #move top left