fix: 修复 1005.K次取反后最大化的数组和 js 代码箭头函数错误

This commit is contained in:
dd
2023-05-28 22:42:49 +08:00
parent 60a2d4bfa7
commit ff5c98184e

View File

@ -189,9 +189,9 @@ var largestSumAfterKNegations = function(nums, k) {
nums[nums.length-1] = - nums[nums.length-1]
k--;
}
return nums.reduce((a, b) => {
a + b
})
// 使用箭头函数的隐式返回值时,需使用简写省略花括号,否则要在 a + b 前加上 return
return nums.reduce((a, b) => a + b)
};
// 版本二 (优化: 一次遍历)