Created
September 19, 2023 23:05
-
-
Save faheemsharif-me/b513a3b059b9c6899d14684bd6d7ccf4 to your computer and use it in GitHub Desktop.
Find Duplicate Number in Python, Time Complexity 0(N), Space Complexity 0(N)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def findDuplicate(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: int | |
| """ | |
| for i in range(len(nums)): | |
| if nums[abs(nums[i])] < 0: | |
| return abs(nums[i]) | |
| nums[abs(nums[i])] = -nums[abs(nums[i])] | |
| # Main Call | |
| nums = [1,3,4,2,2] | |
| solution = Solution() | |
| print(solution.findDuplicate(nums)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment