C++ solution


  • 0
    Z
    class Solution {
    public:
        int maxDistance(vector<vector<int>>& arrays) {
            int max_ret = -95535, maxl_rear = -95535, maxr_rear = -95535;
            for(int li = 0, ri = arrays.size() - 1; ri >= 0; ++li, --ri) {
                int left = arrays[li][0], right = arrays[li][arrays[li].size() - 1];
                max_ret = max(max_ret, maxl_rear - left);
                maxl_rear = max(maxl_rear, right);
                left = arrays[ri][0], right = arrays[ri][arrays[ri].size() - 1];
                max_ret = max(max_ret, maxr_rear - left);
                maxr_rear = max(maxr_rear, right);
            }
            return max_ret;
        }
    };
    

Log in to reply
 

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