1228. Missing Number In Arithmetic Progression

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

Содержание

LeetCode problem 1228

class Solution:
    def missingNumber(self, arr: List[int]) -> int:
        n = len(arr)
        d = (arr[-1] - arr[0]) // n
        for i in range(1, n):
            if arr[i] != arr[i - 1] + d:
                return arr[i - 1] + d
        return arr[0]