mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
26 lines
489 B
Python
26 lines
489 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def compare_two_tops(array) -> int:
|
|
|
|
for i in range(len(array)):
|
|
array[i] *= -1
|
|
|
|
heapq.heapify(array)
|
|
|
|
while len(array) > 1:
|
|
|
|
val1 = heapq.heappop(array)
|
|
val2 = heapq.heappop(array)
|
|
|
|
if val1 != val2:
|
|
heapq.heappush(array, val1 - val2)
|
|
|
|
if array:
|
|
return -heapq.heappop(array)
|
|
|
|
return 0
|
|
|