class Solution:def canMakeArithmeticProgression(self, arr: List[int]) -> bool:# 对数组进行排序arr.sort()# 计算公差diff = arr[1] - arr[0]# 从第二个元素开始逐个检查差值是否一致for i in range(1, len(arr) - 1):if arr[i + 1] - arr[i] != diff:return Falsereturn True
void bubbleSort(int* arr, int arrSize) {for (int i = 0; i < arrSize - 1; i++) {for (int j = 0; j < arrSize - i - 1; j++) {if (arr[j] > arr[j + 1]) {// 交换元素int temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}
… // 从第二个元素开始逐个检查差值是否一致for (int i = 1; i < arrSize - 1; i++) {if (arr[i + 1] - arr[i] != diff) {return false;}}return true;
}