Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9aaf02c

Browse files
1005、K次取反后最大化的数组和,暴力解法,java
1 parent 29e1a07 commit 9aaf02c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎problems/1005.K次取反后最大化的数组和.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,23 @@ class Solution {
145145
}
146146
}
147147
```
148-
148+
```java
149+
//暴力解法
150+
class Solution {
151+
public int largestSumAfterKNegations(int[] nums, int k) {
152+
int count = 0;
153+
//循环k次
154+
for( int i = 0; i < k; i++ ){
155+
Arrays.sort( nums );
156+
nums[0] = -nums[0];//把最小值换成其相反数
157+
}
158+
for ( int num : nums ){
159+
count += num;//累加
160+
}
161+
return count;
162+
}
163+
}
164+
```
149165
### Python
150166
```python
151167
class Solution:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /