mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
added solution and modified README.md for problem 11
This commit is contained in:
parent
11ea4be19f
commit
7b93a8fe37
@ -10,6 +10,7 @@ LeetCode
|
||||
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [C](./src/2.c)|Medium|
|
||||
|3|[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [C](./src/3.c)|Medium|
|
||||
|4|[Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [C](./src/4.c)|Hard|
|
||||
|11| [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [C](./src/11.c)|Medium|
|
||||
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [C](./src/20.c)|Easy|
|
||||
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C](./src/21.c)|Easy|
|
||||
|24|[Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [C](./src/24.c)|Medium|
|
||||
|
30
leetcode/src/11.c
Normal file
30
leetcode/src/11.c
Normal file
@ -0,0 +1,30 @@
|
||||
//Fucntion to calculate min of values a and b
|
||||
int min(int a, int b){
|
||||
return ((a<b)?a:b);
|
||||
}
|
||||
|
||||
//Two pointer approach to find maximum container area
|
||||
int maxArea(int* height, int heightSize){
|
||||
|
||||
//Start with maximum container width
|
||||
int start = 0;
|
||||
int end = heightSize-1;
|
||||
int res = 0;
|
||||
|
||||
while(start<end){
|
||||
//Calculate current area by taking minimum of two heights
|
||||
int currArea = (end-start)*min(height[start],height[end]);
|
||||
|
||||
if(currArea>res)
|
||||
res = currArea;
|
||||
|
||||
if(height[start]<height[end])
|
||||
start = start + 1;
|
||||
else
|
||||
end = end - 1;
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user