Skip to content

Commit 98062a1

Browse files
committed
Week6 Solutions ver1
1 parent e52bc11 commit 98062a1

File tree

2 files changed

+46
-0
lines changed

2 files changed

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

valid-parentheses/hoyeongkwak.java

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

0 commit comments

Comments
 (0)