알고리즘 17 - Invert values

tamagoyakii·2021년 10월 6일
0

알고리즘

목록 보기
17/89

Q.

Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.

invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
Notes:
All values are greater than INT_MIN
The input should be modified, not returned.

A)

#include <stddef.h>

void invert(int *values, size_t values_size) {
  for (size_t i = 0; i < values_size; i++)
    values[i] *= -1;
}

0개의 댓글