Skip to content

Commit 0fe4362

Browse files
committed
container with most water ์ถ”๊ฐ€
1 parent d206b72 commit 0fe4362

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# ์—ฐ๊ด€ ๋งํฌ
2+
- [๋ฌธ์ œ ํ’€์ด ์Šค์ผ€์ค„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [๋‹ต์•ˆ ์ฝ”๋“œ ์ œ์ถœ๋ฒ•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- ๋ฌธ์ œ ๋งํฌ : https://leetcode.com/problems/container-with-most-water/description/
7+
- ๋ฌธ์ œ ์ด๋ฆ„ : Container with most water
8+
- ๋ฌธ์ œ ๋ฒˆํ˜ธ : 11
9+
- ๋‚œ์ด๋„ : medium
10+
- ์นดํ…Œ๊ณ ๋ฆฌ :
11+
12+
# ๋ฌธ์ œ ์„ค๋ช…
13+
14+
๋‘ ์ง€์ ์„ ๋ฒฝ์œผ๋กœ ์„ ์ •ํ•ด, ์ตœ๋Œ€์˜ ๋ฌผ์ด ๋‹ด๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ
15+
16+
17+
# ์•„์ด๋””์–ด
18+
- two pointer
19+
20+
# โœ… ์ฝ”๋“œ (Solution)
21+
22+
## brute force
23+
24+
```cpp
25+
class Solution {
26+
public:
27+
int maxArea(vector<int>& height) {
28+
int maxSize = 0;
29+
for(int i=0;i<height.size();i++){
30+
for(int j=i+1;j<height.size();j++){
31+
maxSize = max(maxSize, (j-i)*min(height[j], height[i]));
32+
}
33+
}
34+
return maxSize;
35+
}
36+
};
37+
```
38+
- brute force
39+
- O(n ^ 2)
40+
- tle
41+
## two pointer
42+
43+
```cpp
44+
class Solution {
45+
public:
46+
int maxArea(vector<int>& height) {
47+
int left = 0, right = height.size()-1;
48+
int maxArea = 0;
49+
50+
while(left<right){
51+
maxArea = max((right-left) * min(height[left], height[right]), maxArea);
52+
53+
if(height[left]>height[right]){
54+
right--;
55+
}else{
56+
left++;
57+
}
58+
}
59+
return maxArea;
60+
}
61+
};
62+
63+
```
64+
- two pointer
65+
- O(n)
66+
67+
# ๐Ÿ” ์ฝ”๋“œ ์„ค๋ช…
68+
69+
70+
# ์ตœ์ ํ™” ํฌ์ธํŠธ (Optimality Discussion)
71+
- two pointer
72+
73+
# ๐Ÿงช ํ…Œ์ŠคํŠธ & ์—ฃ์ง€ ์ผ€์ด์Šค
74+
75+
# ๐Ÿ“š ๊ด€๋ จ ์ง€์‹ ๋ณต์Šต
76+
77+
# ๐Ÿ” ํšŒ๊ณ 
78+
79+

0 commit comments

Comments
ย (0)