You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Keep swap the value at position nums[index]-1 and index if value at position nums[index]-1 is not equal to nums[index].
# This can help to eliminate the problem causes by duplicate valid values in nums array at corresponding position.
while nums[index] > 0 and nums[index] <= len(nums) and nums[nums[index]-1] != nums[index]: # nums[index]-1 != index can cause the infinite while loop if duplicate valid values at corresponding position.