0624.cpp (448B)
1 class Solution { 2 public: 3 int maxDistance(vector<vector<int>> &arrays) const { 4 int mini = arrays[0].front(); 5 int maxi = arrays[0].back(); 6 int res = 0; 7 8 for (int i = 1; i < size(arrays); i++) { 9 res = max({res, arrays[i].back() - mini, maxi - arrays[i].front()}); 10 mini = min(mini, arrays[i].front()); 11 maxi = max(maxi, arrays[i].back()); 12 } 13 14 return res; 15 } 16 };