题解 | #数组中重复的数字#
数组中重复的数字
http://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524
利用数组方法array.splice删除重复元素,当检测到重复元素后,输出该删除元素
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型一维数组
* @return int整型
*/
function duplicate( numbers ) {
if(numbers.length==0)
return -1
else
{
for(let i=0;i<numbers.length;i++){
for(let j=i+1;j<numbers.length;j++){
if(numbers[i]==numbers[j])
return(numbers.splice(j,1))
}
}
}
// write code here
}
module.exports = {
duplicate : duplicate
};

传音控股公司福利 358人发布