LC rotate-array hint 看不懂

189. Rotate Array

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.

赋值时候会覆盖,需要引入额外的辅助变量进行存储

1 Like

主要是不懂这个地方的 cyclic-dependencies