mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-29 16:53:12 +03:00
Merge pull request #468 from jaibhageria/leetcode-algorithm-problem11
added solution and modified README.md for problem 11
This commit is contained in:
commit
2e692eddeb
@ -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
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