Created
November 4, 2017 21:05
-
-
Save cixuuz/a69121f36d159a09b0f0efd8a9d29409 to your computer and use it in GitHub Desktop.
[624. Maximum Distance in Arrays] #leetcode
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: | |
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