Created
April 3, 2022 09:33
-
-
Save mdpabel/bde19baaa2b8eec8ad549033539b5a07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
# @param A : tuple of integers | |
# @return an integer | |
def maximumGap(self, A): | |
n = len(A) | |
nums = [] | |
for item in enumerate(A): | |
nums.append(item) | |
def cmp(a): | |
return a[1] | |
nums.sort(key=cmp) | |
max_distance = 0 | |
min_num = nums[0][0] | |
for num in nums: | |
if num[0] <= min_num: | |
min_num = num[0] | |
else: | |
max_distance = max(max_distance, num[0] - min_num) | |
return max_distance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment