Hi,
The solution has condition & A[i] != i + 1, which seems to be already covered by A[A[i] - 1] != A[i]. Because if A[i] == i + 1, then A[A[i] - 1] == A[i + 1 - 1] == A[i], isn’t it?
Thanks!
Hi,
The solution has condition & A[i] != i + 1, which seems to be already covered by A[A[i] - 1] != A[i]. Because if A[i] == i + 1, then A[A[i] - 1] == A[i + 1 - 1] == A[i], isn’t it?
Thanks!
Hey Ray,
You are right, and the reason I put that before is because we want to prevent unnecessary swaps for two identical indices. However, I think readability trumps efficiency here. Therefore, I just remove that check.