Super easy Python solution with the use of '~' for indexing


  • 0
    K
    class Solution(object):
        def rotate(self, m):
            """
            :type matrix: List[List[int]]
            :rtype: void Do not return anything, modify matrix in-place instead.
            """
            n = len(m)
            for i in xrange(n / 2):
                for j in xrange((n+1) / 2):
                    m[i][j], m[j][~i], m[~i][~j], m[~j][i] = m[~j][i], m[i][j], m[j][~i], m[~i][~j]
    

    For those of you who don't know about ~, try it out yourself :)


  • 0
    R

    Could you care to explain what ~ does in this scenario ?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.