Untitled

mail@pastecode.io avatar
unknown
python
a year ago
387 B
4
Indexable
Never
class Solution:
    def minimumOperations(self, nums: List[int]) -> int:
        d = deque(nums)
        res = 0
        while len(d) > 1:
            if d[0] == d[-1]:
                d.pop()
                d.popleft()
                continue
            res += 1
            p,a = (d.popleft,d.appendleft) if d[0]<d[-1] else (d.pop,d.append)
            a(p()+p())
        return res