Python five lines o(N) solution

  • 0

    class Solution(object):
    def maxDistance(self, arrays):
    :type arrays: List[List[int]]
    :rtype: int

        result, min_value, max_value = 0, arrays[0][0], arrays[0][-1]
        for array in arrays[1:]:
            result = max(result, array[-1]-min_value, max_value-array[0])
            max_value, min_value = max(array[-1], max_value), min(min_value, array[0])
        return result

Log in to reply

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