寻找重复数
function findDuplicate(nums) { let map = new Map() for(let i = 0;i < nums.length;i++){ let item= nums[i] if(map.has(item)){ return item }else{ map.set(item,1) } } return undefined }
快慢指针
const findDuplicate = (nums) => { let slow = 0, fast = 0; do { slow = nums[slow]; fast = nums[nums[fast]]; } while (slow != fast); slow = 0; while (slow != fast) { slow = nums[slow]; fast = nums[fast]; } return slow; };
以自己现在的努力程度,还没有资格和别人拼天赋