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上想 先想解决办法
这篇博客探讨了JavaScript中使用数组`letarr=[1,2,3,4]`和Map对象进行操作的问题,展示了如何在遍历数组时更新Map,并找到最大值。通过示例代码,解释了在不依赖动态规划的情况下解决问题的方法。
285

被折叠的 条评论
为什么被折叠?



