can you explain how to solve the problem 442(find duplicate in array) by similiar way?I have thinked about it but i think it's different, Thank you !


  • 0
    F

  • 0
    Q

    @fuhao0728
    just view it as a perfect linear inplace hash, with self-encoding mark visited.
    to make it clearer, try not to mutate the array itself, instead try with an extra array.
    and run an example such as below with pen-and-paper, or on your computer.
    Example: Input: [4,3,2,7,8,2,3,1] Output: [5,6]
    extra array [0,0.0,....]
    --> [0,0,0,1,0,0....] // or inplace [4,3,2,-7,8,2,3,1]
    --> ....


Log in to reply
 

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