1502. Can Make Arithmetic Progression From Sequence

1502. Can Make Arithmetic Progression From Sequence #

题目 #

  • 给你一个数字数组 arr
  • 如果一个数列中,任意相邻两项的差总等于同一个常数,那么这个数列就称为 等差数列
  • 如果可以重新排列数组形成等差数列,请返回 true ;否则,返回 false

思路 #

模拟 #

代码 #

模拟 #

class Solution {
    public boolean canMakeArithmeticProgression(int[] arr) {
        Arrays.sort(arr);
        int diff = arr[0]-arr[1];
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i]-arr[i+1] != diff) return false;
        }
        return true;
    }
}