Very simple C++ solution


  • 0
    S

    "Firstly, we put each element x in nums[x - 1]" : This is done using a simple loop where in we swap nums[i] with nums[nums[i]-1] until they become equal. The point to note here is that only when they become equal we increment i.

    "we check through the array. If a number x doesn't present in nums[x - 1], then x is absent." and nums[x-1] is a duplicate value so we add it to the res vector.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.