File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int maxArea (int [] height ) {
3+ int left =0 ;
4+ int right =height .length -1 ;
5+ int max =0 ;
6+
7+ while (left <right ) {
8+ int water = (right -left ) * Math .min (height [left ], height [right ]);
9+ max = Math .max (max , water );
10+
11+ if (height [left ]<height [right ]) {
12+ left ++;
13+ } else {
14+ right --;
15+ }
16+ }
17+ return max ;
18+ }
19+ }
20+
21+
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean isValid (String s ) {
3+ Deque <Character > stack = new ArrayDeque <>();
4+
5+ for (char c : s .toCharArray ()) {
6+ if (c == '(' || c =='{' || c =='[' ) {
7+ stack .push (c );
8+ }
9+ if (c == ')' ) {
10+ if (stack .isEmpty () || stack .peek () != '(' ) return false ;
11+ stack .pop ();
12+ }
13+ if (c == '}' ) {
14+ if (stack .isEmpty () || stack .peek () != '{' ) return false ;
15+ stack .pop ();
16+ }
17+ if (c == ']' ) {
18+ if (stack .isEmpty () || stack .peek () != '[' ) return false ;
19+ stack .pop ();
20+ }
21+ }
22+ return stack .isEmpty ();
23+ }
24+ }
25+
26+
You can’t perform that action at this time.
0 commit comments