diff --git a/container-with-most-water/doh6077.py b/container-with-most-water/doh6077.py new file mode 100644 index 000000000..907db9516 --- /dev/null +++ b/container-with-most-water/doh6077.py @@ -0,0 +1,16 @@ +# 11. Container With Most Water + +# Use two pointesr +class Solution: + def maxArea(self, height: List[int]) -> int: + left, right = 0, len(height) -1 + container = 0 + + while left < right: + cal = ((right - left) * min(height[left], height[right])) + container = max(container, cal) + if height[left] > height[right]: + right -= 1 + else: + left += 1 + return container diff --git a/valid-parentheses/doh6077.py b/valid-parentheses/doh6077.py new file mode 100644 index 000000000..483b76cae --- /dev/null +++ b/valid-parentheses/doh6077.py @@ -0,0 +1,16 @@ +# Use stack and Hashmap +class Solution: + def isValid(self, s: str) -> bool: + match = {")": "(", "}": "{", "]": "["} + stack = [] + + for ch in s: + if ch in match: + if stack and stack[-1] == match[ch]: + stack.pop() + else: + return False + else: + stack.append(ch) + return True if not stack else False +