Skip to content

Latest commit

 

History

History
31 lines (28 loc) · 954 Bytes

数组中只出现一次的数字.md

File metadata and controls

31 lines (28 loc) · 954 Bytes
note
createdAt modifiedAt tags id
2020-05-14 12:38:12 UTC
2020-05-16 12:33:15 UTC
考点/知识迁移能力
难度/3

数组中只出现一次的数字

#考点/知识迁移能力 #难度/3 牛客网

题目描述

一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。

答案

function FindNumsAppearOnce(array) {
  // write code here
  // return list, 比如[a,b],其中ab是出现一次的两个数字
  if (array.length == 0) {
    return [];
  }
  var temp = [];
  for (var i = 0; i < array.length; i++) {
    if (array.indexOf(array[i]) == array.lastIndexOf(array[i])) {
      temp.push(array[i]);
    }
  }
  return temp.sort();
}