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