Merge branch 'master' into master

This commit is contained in:
程序员Carl
2022-05-06 09:27:21 +08:00
committed by GitHub
67 changed files with 668 additions and 2741 deletions

View File

@@ -211,6 +211,7 @@ var largestSumAfterKNegations = function(nums, k) {
};
```
### C
```c
#define abs(a) (((a) > 0) ? (a) : (-(a)))
@@ -250,5 +251,30 @@ int largestSumAfterKNegations(int* nums, int numsSize, int k){
}
```
### TypeScript
```typescript
function largestSumAfterKNegations(nums: number[], k: number): number {
nums.sort((a, b) => Math.abs(b) - Math.abs(a));
let curIndex: number = 0;
const length = nums.length;
while (curIndex < length && k > 0) {
if (nums[curIndex] < 0) {
nums[curIndex] *= -1;
k--;
}
curIndex++;
}
while (k > 0) {
nums[length - 1] *= -1;
k--;
}
return nums.reduce((pre, cur) => pre + cur, 0);
};
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>