function twoSum( numbers , target ){// write code here
let map = new Map()for(let i=0;i<numbers.length;i++){if(map.has(target-numbers[i])){return[i+1,map.get(target-numbers[i])+1].sort((a,b)=> a-b)}
map.set(numbers[i],i)}}
51 数组中出现次数超过一半的数字
function MoreThanHalfNum_Solution(numbers){// write code here
let map = new Map()for(let i=0;i<numbers.length;i++){if(map.get(numbers[i])==undefined){
map.set(numbers[i],1)}else{
map.set(numbers[i],map.get(numbers[i])+1)}if(map.get(numbers[i])> numbers.length/2){return numbers[i]}}}
52 数组中只出现一次的两个数字
function FindNumsAppearOnce( array ){// write code here
let map = new Map()
let filter =[]for(let i in array){if(map.get(array[i])== undefined){
map.set(array[i],1)}else{
map.set(array[i],map.get(array[i])+1)}if(map.get(array[i])==2){
filter.push(array[i])}}
let res = array.filter(a=>!filter.includes(a))
res.sort((a,b)=>a-b)return res
}
53 缺失的第一个正整数
function minNumberDisappeared( nums ){// write code here
let map = new Map()for(let i in nums){
map.set(nums[i],true)}
let j
for(j=1;j<=nums.length;j++){if(!map.has(j))return j
}return j
}
function threeSum( num ){// write code here
let res =[]
let set = new Set()for(let i=0;i<num.length-2;i++){
let map = new Map()for(let j=i+1;j<num.length;j++){if(map.has(num[j])){
let cur = map.get(num[j]).concat(num[j]).sort((a,b)=>a-b)if(!set.has(JSON.stringify(cur))){
set.add(JSON.stringify(cur))
res.push(cur)}}else{
map.set(0-num[i]-num[j],[num[i],num[j]])}}}return res
}