Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created November 4, 2017 21:05
Show Gist options
  • Save cixuuz/a69121f36d159a09b0f0efd8a9d29409 to your computer and use it in GitHub Desktop.
Save cixuuz/a69121f36d159a09b0f0efd8a9d29409 to your computer and use it in GitHub Desktop.
[624. Maximum Distance in Arrays] #leetcode
class Solution:
def maxDistance(self, arrays):
"""
:type arrays: List[List[int]]
:rtype: int
"""
# min and max store the min and max value in previous arrays
_min = arrays[0][0]
_max = arrays[0][-1]
res = 0
for a in arrays[1:]:
res = max(res, abs(_min - a[-1]))
res = max(res, abs(_max - a[0]))
_min = min(_min, a[0])
_max = max(_max, a[-1])
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment