File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change
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
+
You canโt perform that action at this time.
0 commit comments