Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对于列表,说
1,2,3,4,5,6
当有人说将阵列逆时针/逆时针旋转 2 次时,有两种方法可以做到:
case 1: 1st time: 6,1,2,3,4,5 2nd time: 5,6,1,2,3,4 case 2: 1st time: 2,3,4,5,6,1 2nd time: 3,4,5,6,1,2
在这两种情况下,我应该考虑哪一种?
您应该将案例 2 视为逆时针,如下所示:
* 1 6 2 5 3 4
顺时针旋转的方向1 -> 2 -> 3 -> ... -> 6如下,
1 -> 2 -> 3 -> ... -> 6
* 6 5 1 4 2 3
和逆时针旋转的方向1 -> 6 -> 5 -> ... -> 2一样。
1 -> 6 -> 5 -> ... -> 2
* 2 1 3 6 4 5
您应该将案例 1 视为顺时针方向。因为,您正在将值转移到顺时针方向的右侧。第二种情况是逆时针方向。