-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatNumber.js
More file actions
30 lines (29 loc) · 771 Bytes
/
Copy pathrepeatNumber.js
File metadata and controls
30 lines (29 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* param Array<number>
* return number
*/
const repeatNumer = (data)=>{
let temp=0;
if(data== null || data.length ==0 ){
return false;
}
for(let item of data){
if(item <0 || item>data.length -1){
return false;
}
}
for(let i =0;i<data.length;i++){
while(data[i]!=i){
if(data[i] == data[data[i]]){
temp = data[i];
return true;
}
let tempData = data[i];
data[i] = data[tempData];
data[tempData]= tempData;
}
}
}
console.log("repeatNumer([2,3,1,0,2,5,3]):", repeatNumer([2,3,1,0,2,5,3]));
console.log("repeatNumer([2,3,1,0,4,5,13]):", repeatNumer([2,3,1,0,4,5,13]));
repeatNumer([2,3,1,0,4,5,13])