let arr = [1,2,3,4],
difference = 1;
let map = new Map();
let max = 0;
arr.forEach((v) => {
const temp = map.get(v - difference) || 0;
map.set(v, temp ? temp + 1 : 1);
max = Math.max(max, temp + 1);
});
console.log(max, map);
写在这 提醒我 不要每次都往dp上想 先想解决办法