Find the Duplicate Number
<p>Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.</p>
<p>My solution:</p>
<pre><code>def findDuplicate(nums):
    slow = fast = finder = 0
    while fast is not None:
    
    
        slow = nums[slow]
        fast = nums[nums[fast]]
    
        if fast is slow:
            return slow
       
   return False

nums = [1,2,2,3,4]
print findDuplicate(nums)
</code></pre>
<p>My above solution works and gives me o/p 2 but it doesn't work for every input for example it doesn't work for <code>[11,15,17,17,14]</code> or <code>[3,1,2,6,2,3]</code> and gives me error IndexError: list index out of range. I am not able to find patterns and am not able to track down the exact problem. Also tried to change my while condition:</p>
<pre><code>while fast is not None and nums[nums[fast]] is not None:
</code></pre>
<p>your help will be greatly appreciated! Thank you.</p>