Skip to content

Commit aa657db

Browse files
authored
Merge pull request #2208 from mandel-17/main
[mandel-17] WEEK 06 solutions
2 parents c1cfd01 + 455955e commit aa657db

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxArea(self, height: List[int]) -> int:
3+
max_area = 0
4+
left, right = 0, len(height) - 1
5+
while left < right:
6+
area = (right - left) * min(height[left], height[right])
7+
max_area = max(area, max_area)
8+
if height[left] <= height[right]:
9+
left += 1
10+
else:
11+
right -= 1
12+
return max_area
13+

valid-parentheses/mandel-17.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class ArrayStack:
2+
def __init__(self, capacity):
3+
self.capacity = capacity
4+
self.array = [None] * self.capacity
5+
self.top = -1
6+
7+
def isEmpty(self):
8+
return self.top == -1
9+
10+
def isFull(self):
11+
return self.top == self.capacity - 1
12+
13+
def push(self, item):
14+
if not self.isFull():
15+
self.top += 1
16+
self.array[self.top] = item
17+
else:
18+
pass
19+
20+
def pop(self):
21+
if not self.isEmpty():
22+
self.top -= 1
23+
return self.array[self.top+1]
24+
else:
25+
pass
26+
27+
class Solution:
28+
def isValid(self, s: str) -> bool:
29+
stack = ArrayStack(100)
30+
for ch in s:
31+
if ch in ('(', '[', '{'):
32+
stack.push(ch)
33+
elif ch in (')', ']', '}'):
34+
if stack.isEmpty():
35+
return False
36+
else:
37+
left = stack.pop()
38+
if (ch == ')' and left != '(') or \
39+
(ch == ']' and left != '[') or \
40+
(ch == '}' and left != '{'):
41+
return False
42+
return stack.isEmpty()
43+
44+

0 commit comments

Comments
 (0)