You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int curHeight = height[i] <= height[j] ? height[i] : height[j];
if (curHeight > maxHeight) {
ans = Math.max(ans, curHeight * (j - i));
maxHeight = curHeight;
}
// Move the pointer with the smaller height
if (height[i] <= height[j]) {
i++;
} else {
j--;
}
}
return ans;
}
}
/*
* Time complexity: O(n), n is the length of the height
* Space complexity: O(1)
*
* Notes:
* This explanation is really impresive: https://leetcode.com/problems/container-with-most-water/discuss/6099/Yet-another-way-to-see-what-happens-in-the-O(n)-algorithm