File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int maxArea (int [] height ) {
3+ // λμ΄ μμλλ‘ μ λ ¬ν΄μ, μ²μλΆν° 2κ°μ© μ‘μμ λλΉλ₯Ό ꡬνλ λ°©λ² => n^2
4+ // ν΄μ€ μ°Έκ³ ν¨. -> ν¬μΈν° 2κ°λ₯Ό λ¬μ μμΈ‘μμ μμν΄μ μ€κ°μ λ§λ λκΉμ§ μ΅λκ°μ ꡬνλ€
5+ int s = 0 ;
6+ int e = height .length - 1 ;
7+ int result = 0 ;
8+
9+ while (s < e ) {
10+ int h = height [s ] < height [e ] ? height [s ] : height [e ];
11+ int w = e - s ;
12+ int cur = h * w ;
13+ if (cur > result ) {
14+ result = cur ;
15+ }
16+
17+ if (height [s ] < height [e ]) {
18+ s ++;
19+ } else {
20+ e --;
21+ }
22+ // System.out.println(s + " " + e + " " + cur);
23+ }
24+ return result ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean isValid (String s ) {
3+ // μ€ν... 머리μμ λ μ€λ₯΄λ μκ°μ μλλ° μ λ¦¬κ° μλ..
4+ // ν΄μ€ μ½μ
5+
6+ Map <Character , Character > parens = new HashMap <>();
7+ parens .put ('(' , ')' );
8+ parens .put ('{' , '}' );
9+ parens .put ('[' , ']' );
10+
11+ Stack <Character > stack = new Stack <>();
12+
13+ for (char c : s .toCharArray ()) {
14+ if (parens .containsKey (c )) {
15+ stack .push (c );
16+ } else {
17+ if (stack .isEmpty () || c != parens .get (stack .pop ())) {
18+ return false ;
19+ }
20+ }
21+ }
22+
23+ return stack .isEmpty ();
24+ }
25+ }
You canβt perform that action at this time.
0 commit comments