concise python O(n)

  • 1
    def maxDistance(self, arrays):
    	res = 0
    	maxx = arrays[0][-1]
    	minn = arrays[0][0]
    	for i in xrange(1, len(arrays)):
    		newdist = max(abs(arrays[i][0] - maxx), abs(arrays[i][-1] - minn))
    		res = max(res, newdist)
    		maxx = max(maxx, arrays[i][-1])
    		minn = min(minn, arrays[i][0])
    	return res

Log in to reply

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