Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container With Most Water #34

Closed
Tracked by #100
fkdl0048 opened this issue Sep 28, 2024 · 0 comments
Closed
Tracked by #100

Container With Most Water #34

fkdl0048 opened this issue Sep 28, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Sep 28, 2024

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

        while (left < right){
            int currentArea = min(height[left], height[right]) * (right - left);
            maxArea = max(maxArea, currentArea);
            if (height[left] < height[right])
                left++;
            else
                right--;
        }

        return maxArea;
    }
};
  • 생각보다 쉬운 문제.. 물 면접을 구하는 문제인데, 너비와 높이가 최대 면적을 구하는 수에 영향을 주기에 투포인터 전략으로 하나씩 줄여나가며 구하면 된다.
@fkdl0048 fkdl0048 mentioned this issue Sep 28, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Sep 28, 2024
@fkdl0048 fkdl0048 added this to Todo Sep 28, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Sep 28, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Sep 28, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Sep 28, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Sep 29, 2024
This was referenced Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant