Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

rotate matrix 90 degrees clockwise

def rotate(matrix):
    rows = len(matrix)
    cols = len(matrix[0])
    res = []
    for i in range(cols):
        temp = []
        for j in range(rows):
            temp.append(matrix[j][i])
        res.append(temp[::-1])

    return res


matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(rotate(matrix))
 
PREVIOUS NEXT
Tagged: #rotate #matrix #degrees #clockwise
ADD COMMENT
Topic
Name
4+5 =