Given an array of integers nums containing n + 1 integers
where each integer is in the range [1, n] inclusive.
There is only one repeated number in nums, return this repeated number.
You must solve the problem without modifying
the array nums and uses only constant extra space.
제한사항
- 1 <= n <= 105
- nums.length == n + 1
- 1 <= nums[i] <= n
- All the integers in nums appear only once except for precisely
- one integer which appears two or more times.
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
nums.sort() #정렬
for i in range(len(nums)):
if(nums[i] == nums[i+1]) :
return nums[i]