标签:return targe sre function tar key code pre aaa
let str = "aaabbccccddddd"
function longSre(str) {
let zifu;
let max = 0;
let arr = str.split(‘‘)
let map = new Map()
for (let i = 0; i < arr.length; i++) {
if (map.has(arr[i])) {
let num = map.get(arr[i]) + 1
map.set(arr[i], num)
} else {
map.set(arr[i], 1)
}
}
for (let item of map.keys()) {
if (map.get(item) > max) {
zifu = item
max = map.get(item)
}
}
console.log(zifu)
console.log(max)
}
longSre(str)
var twoSum = function(nums, target) {
let map=new Map()
for(let i=0;i<nums.length;i++){
let dif=target-nums[i]
if(map.has(dif)){
return [map.get(dif),i]
}else{
map.set(nums[i],i)
}
}
};
标签:return targe sre function tar key code pre aaa
原文地址:https://www.cnblogs.com/lceihen/p/14645698.html