Find All Duplicates in an Array
Find every value that appears twice, using the array itself as the seen-set.
The problem
Implement Solution.findDuplicates(nums). Every value in nums is between 1 and len(nums), and each value appears once or twice. Return every value that appears twice, in any order. Use only O(1) extra space besides the returned list; you may modify nums. For example, [4, 3, 2, 7, 8, 2, 3, 1] returns [2, 3]. 1 <= len(nums) <= 100000.
Starter code
class Solution:
def findDuplicates(self, nums):
passPublic examples
nums = [4, 3, 2, 7, 8, 2, 3, 1]gives[2, 3]nums = [1]gives[]nums = [3, 1, 3, 2, 2]gives[3, 2]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
