阅微客栈 » 头脑风暴

How to in-place right-rotate a two dimensional array?

(1 post)
  • 发起于 7 月 之前,作者 szuxjq
  1. szuxjq
    Member

    某知名网站的讨论,
    For example, given a MxN (3x4) two dimensional array

    1, 2, 3, 4
    5, 6, 7, 8
    9,10,11,12

    You need to rearrange it into:

    9 , 5, 1,
    10, 6, 2,
    11, 7, 3,
    12, 8, 4

    Write a function to do it in-place.

    e.g. M=3, N=4, and a memory block contains:
    [1,2,3,4,5,6,7,8,9,10,11,12]

    You need to change the memory block into
    [9,5,1,10,6,2,11,7,3,12,8,4]

    "In-place" means memory constaint is O(1).

    发布于 7 月 之前 #

该主题的 RSS Feed

回复

你必须 登录 后发帖。