题解 | #数组中重复的数字#
数组中重复的数字
https://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524
#include <fstream> class Solution { public: int duplicate(vector<int>& numbers) { int n = numbers.size(); if(n<1) return -1; for(int i = 0;i<n;i++){ while (numbers[i]!=i) { if(numbers[i]==numbers[numbers[i]]){ return numbers[i]; } swap(numbers[i], numbers[numbers[i]]); } } return -1; } };