Skip to content

Commit fcfa4e1

Browse files
authored
Merge pull request #2184 from hjeomdev/main
[hjeomdev] WEEK 06 solutions
2 parents 70c9b19 + be51247 commit fcfa4e1

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
Β (0)