Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions container-with-most-water/socow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
📚 11. Container With Most Water

📌 문제 요약
- 높이 배열이 주어졌을 때, 두 막대 사이에 담을 수 있는 물의 최대 넓이 구하기
- 넓이 = min(두 높이) × 거리

🎯 핵심 알고리즘
- 패턴: 투 포인터 (Two Pointer)
- 시간복잡도: O(n)
- 공간복잡도: O(1)

💡 핵심 아이디어
1. 양 끝에서 시작 (left = 0, right = n-1)
2. 현재 넓이 계산 후 최댓값 갱신
3. 더 작은 높이 쪽을 이동 → 더 큰 높이를 찾을 가능성!
"""

class Solution:
def maxArea(self, height: list[int]) -> int:
left, right = 0, len(height) - 1
max_area = 0

while left < right:
h = min(height[left], height[right])
w = right - left
max_area = max(max_area, h * w)

if height[left] < height[right]:
left += 1
else:
right -= 1

return max_area
18 changes: 18 additions & 0 deletions valid-parentheses/socow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def isValid(self, s: str) -> bool:

if len(s) % 2 ==1:
return False

pair = {")":"(","}":"{","]":"["}
all = set(pair.values())
stack = []

for x in s:
if x in all:
stack.append(x)
else:
if not stack or stack[-1] !=pair[x]:
return False
stack.pop()
return not stack