Medium
Given an integer array nums
, rotate the array to the right by k
steps, where k
is non-negative.
题目很简单,就是这一段没看懂:
Hint 4
The other line of thought is a tad bit complicated but essentially it builds on the idea of placing each element in its original position while keeping track of the element originally in that position. Basically, at every step, we place an element in its rightful position and keep track of the element already there or the one being overwritten in an additional variable. We can’t do this in one linear pass and the idea here is based on cyclic-dependencies between elements.