mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 1005.K次取反后最大化的数组和.md
保持Java代码的一致性,使用stream api来返回累加结果。
This commit is contained in:
@ -117,11 +117,8 @@ class Solution {
|
||||
}
|
||||
// 如果K还大于0,那么反复转变数值最小的元素,将K用完
|
||||
if (k % 2 == 1) nums[len - 1] = -nums[len - 1];
|
||||
int result = 0;
|
||||
for (int a : nums) {
|
||||
result += a;
|
||||
}
|
||||
return result;
|
||||
|
||||
return Arrays.stream(nums).sum();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user