4.Find the Duplicate Number
Given an array of integers nums
containing n + 1
integers where each integer is in the range [1, n]
inclusive.
There is only one duplicate number in nums
, return this duplicate number.
Solution: (Using Hashset)
Time Complexity: O(n) , Space Complexity: O(n)
Solution II : Floyd's Tortoise and Hare (Cycle Detection)
Here is how it works:
Time Complexity: O(n) , Space Complexity: O(1)
Last updated