Merge pull request #2106 from GGhhccc/master

fix: 修复 1005.K次取反后最大化的数组和 中 js 代码箭头函数错误
This commit is contained in:
程序员Carl
2023-06-12 06:59:17 +08:00
committed by GitHub

View File

@ -195,9 +195,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)
};
// 版本二 (优化: 一次遍历)