442. Find All Duplicates in an Array
1 | class Solution { |
一样的, 在array中标记. 如果标记的时候发现对应的位置已经被标记过, 那么说明这个元素此时是第二次出现, 那么把它添加到ans中去.
时间复杂度: O(n)
空间复杂度: O(1)
Insist on doing small things, then witness the magic
1 | class Solution { |
一样的, 在array中标记. 如果标记的时候发现对应的位置已经被标记过, 那么说明这个元素此时是第二次出现, 那么把它添加到ans中去.
时间复杂度: O(n)
空间复杂度: O(1)