All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 04, 2024
Last updated : July 01, 2024
Related Topics : Array, Sorting
Acceptance Rate : 69.52 %
int compareHelper(const void* one, const void* two) {
return *((int *) one) - *((int *) two);
}
bool canMakeArithmeticProgression(int* arr, int arrSize) {
qsort(arr, arrSize, sizeof(int), compareHelper);
for (int i = 0; i < arrSize - 2; i++) {
if (!(arr[i] - arr[i + 1] == arr[i + 1] - arr[i + 2])) {
return false;
}
}
return true;
}
class Solution:
def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
arr.sort()
for i in range(len(arr) - 2) :
if not arr[i] - arr[i + 1] == arr[i + 1] - arr[i + 2] :
return False
return True