File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int maxArea (vector<int >& height) {
4+ int left = 0 ;
5+ int right = height.size () - 1 ;
6+ int ans = 0 ;
7+
8+ while (left < right)
9+ {
10+ int cur = (right - left) * min (height[left], height[right]);
11+ if (cur > ans)
12+ ans = cur;
13+ if (height[left] <= height[right])
14+ left++;
15+ else
16+ right--;
17+ }
18+ return ans;
19+ }
20+ };
Original file line number Diff line number Diff line change 1+ /*
2+
3+ */
4+
5+ class Solution {
6+ public:
7+ bool isValid (string s) {
8+ stack<char > st;
9+
10+ for (auto & c : s)
11+ {
12+ if (c == ' )' )
13+ {
14+ if (st.empty () || st.top () != ' (' )
15+ return false ;
16+ st.pop ();
17+ }
18+ if (c == ' }' )
19+ {
20+ if (st.empty () || st.top () != ' {' )
21+ return false ;
22+ st.pop ();
23+ }
24+ if (c == ' ]' )
25+ {
26+ if (st.empty () || st.top () != ' [' )
27+ return false ;
28+ st.pop ();
29+ }
30+ else
31+ st.push ();
32+ }
33+
34+ if (!st.empty ())
35+ return false ;
36+ else
37+ return true ;
38+ }
39+ };
You can’t perform that action at this time.
0 commit comments