09-19 leetcode-0287
链接 287. 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 repeated number in nums, return this repeated number.
You must solve the problem without modifying the array nums and uses only constant extra space.
题解
这题第一种做法就是经典的 bitmap,空间复杂度 O1
1 | class Solution: |
第二种做法是原地数组修改
1 | class Solution: |
Comments