코테준비 - Container With Most Water

정상화·2023년 2월 26일

LeetCode

목록 보기
10/222

Container With Most Water


class Solution {
public:
    int maxArea(vector<int> &height) {
        int l = 0;
        int r = height.size() - 1;
        int max = 0;

        while (l < r) {
            if(height.at(l) > height.at(r)){
                max = std::max(max, (r - l) * height.at(r));
                r--;
            }
            else {
                max = std::max(max, (r - l) * height.at(l));
                l++;
            }
        }

        return max;
    }
};
profile
백엔드 희망

0개의 댓글