Merge pull request #468 from jaibhageria/leetcode-algorithm-problem11

added solution and modified README.md for problem 11
This commit is contained in:
Hai Hoang Dang 2019-10-28 09:25:56 -07:00 committed by GitHub
commit 2e692eddeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -13,6 +13,7 @@ LeetCode
|7|[Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [C](./src/7.c)|Easy|
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [C](./src/8.c)|Medium|
|9|[Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [C](./src/9.c)|Easy|
|11| [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [C](./src/11.c)|Medium|
|12|[Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c)|Medium|
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [C](./src/13.c)|Easy|
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [C](./src/20.c)|Easy|

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;
}