mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
修复1005.K取反后最大化的数组和Java代码K书写错误问题
This commit is contained in:
@ -110,13 +110,13 @@ class Solution {
|
||||
int len = nums.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
//从前向后遍历,遇到负数将其变为正数,同时K--
|
||||
if (nums[i] < 0 && k > 0) {
|
||||
if (nums[i] < 0 && K > 0) {
|
||||
nums[i] = -nums[i];
|
||||
k--;
|
||||
K--;
|
||||
}
|
||||
}
|
||||
// 如果K还大于0,那么反复转变数值最小的元素,将K用完
|
||||
if (k % 2 == 1) nums[len - 1] = -nums[len - 1];
|
||||
if (K % 2 == 1) nums[len - 1] = -nums[len - 1];
|
||||
int result = 0;
|
||||
for (int a : nums) {
|
||||
result += a;
|
||||
|
Reference in New Issue
Block a user