1502. Can Make Arithmetic Progression From Sequence

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1502

class Solution:
    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
        a = min(arr)
        b = max(arr)
        n = len(arr)
        if (b - a) % (n - 1):
            return False
        d = (b - a) // (n - 1)
        s = set(arr)
        return all(a + d * i in s for i in range(n))