Python fast solution


  • 0
    M
    class Solution(object):
        def maxDistance(self, arrays):
            low = arrays[0][0]
            high = arrays[0][-1]
            maxD = 0
            for i in range(1, len(arrays)):
                if abs(arrays[i][0] - high) > maxD:
                    maxD = abs(arrays[i][0] - high)
                if abs(arrays[i][-1] - low) > maxD:
                    maxD = abs(arrays[i][-1] - low)
                if low > arrays[i][0]:
                    low = arrays[i][0]
                if high < arrays[i][-1]:
                    high = arrays[i][-1]
                
            return maxD
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.