1228. Missing Number In Arithmetic Progression

Updated: 2024-03-12
1 min read
[]

On This Page

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]