Skip to content

Commit 293656e

Browse files
committed
Day - 80 work
1 parent 74966b1 commit 293656e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
| Current Status| Stats |
88
| :------------: | :----------: |
9-
| Total Problems | 116 |
10-
| Current Streak | 79 days |
11-
| Longest Streak | 79 ( August 17, 2015 - November 03, 2015 ) |
9+
| Total Problems | 117 |
10+
| Current Streak | 80 days |
11+
| Longest Streak | 80 ( August 17, 2015 - November 04, 2015 ) |
1212

1313
</center>
1414

@@ -193,3 +193,6 @@ Include contains single header implementation of data structures and some algori
193193
|Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.| [missing_number.cpp](leet_code_problems/missing_number.cpp)|
194194
|Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the array.| [find_min_rotated.cpp](leet_code_problems/find_min_rotated.cpp)|
195195
|Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.| [threeSumClosest.cpp](leet_code_problems/threeSumClosest.cpp)|
196+
|Given n non-negative integers a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub>, where each represents a point at coordinate (i, a<sub>i</sub>). n vertical lines are drawn such that the two endpoints of line i is at (i, a<sub>i</sub>) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container.| [maxArea.cpp](leet_code_problems/maxArea.cpp)|
197+
198+

leet_code_problems/maxArea.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).
3+
* n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0).
4+
* Find two lines, which together with x-axis forms a container, such that the container contains the most water.
5+
* Note: You may not slant the container.
6+
*/
7+
8+
#include <iostream>
9+
#include <vector>
10+
#include <limits>
11+
12+
int maxArea(std::vector<int>& height) {
13+
size_t l = 0;
14+
size_t r = height.size() - 1;
15+
int maxAr = std::numeric_limits<int>::min();
16+
while( l < r ) {
17+
int curAr = ( std::min(height[l], height[r]) * ( r - l ));
18+
if ( curAr > maxAr ) {
19+
maxAr = curAr;
20+
}
21+
if ( height[l] < height[r]) {
22+
l++;
23+
} else {
24+
r--;
25+
}
26+
}
27+
return maxAr;
28+
}
29+
30+
void printVec( std::vector<int> & vec ) {
31+
std::cout << "Heights:";
32+
for( auto v : vec ) {
33+
std::cout << v << " ";
34+
}
35+
std::cout << std::endl;
36+
}
37+
38+
int main()
39+
{
40+
std::vector<int> heights{ 4, 5, 1 };
41+
printVec(heights);
42+
std::cout << "Max possible area with above heights:" << maxArea(heights) << std::endl;
43+
return 0;
44+
}

leet_code_problems/run

-8.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)