My solution(C++)


  • 0
    X
    class Solution {
    public:
        int maxDistance(vector<vector<int>>& arrays) {
            int max_distance = 0, prev_min = arrays[0].front(), prev_max = arrays[0].back();
            for (decltype(arrays.size()) i = 1; i < arrays.size(); ++i) {
                max_distance = max(max_distance, abs(prev_min - arrays[i].back()));
                max_distance = max(max_distance, abs(arrays[i].front() - prev_max));
                prev_min = min(prev_min, arrays[i].front());
                prev_max = max(prev_max, arrays[i].back());
            }
            return max_distance;
        }
    };
    

Log in to reply
 

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