added solution and modified README.md for problem 11

This commit is contained in:
Jai Agarwal 2019-10-25 21:50:03 +05:30
parent 11ea4be19f
commit 7b93a8fe37
2 changed files with 31 additions and 0 deletions

View File

@ -10,6 +10,7 @@ LeetCode
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [C](./src/2.c)|Medium| |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| |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| |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| |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| |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| |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
View 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;
}