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
19 changes: 19 additions & 0 deletions container-with-most-water/jylee2033.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 양 끝 포인터를 이동시키며 최대 면적을 찾는 방식으로, Two Pointers 패턴에 속합니다. 효율적인 탐색을 위해 양쪽에서 시작하는 것이 특징입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height) - 1
area = min(height[left], height[right]) * (right - left)

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

new_area = min(height[left], height[right]) * (right - left)
area = max(area, new_area)

return area

# Time Complexity: O(n)
# Space Complexity: O(1)
25 changes: 25 additions & 0 deletions valid-parentheses/jylee2033.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack
  • 설명: 이 코드는 괄호의 유효성을 검사하기 위해 스택을 활용하여 열린 괄호를 저장하고, 닫힌 괄호와 비교하는 방식으로 동작합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution:
def isValid(self, s: str) -> bool:
close_to_open = {')': '(', '}': '{', ']': '['}
stack = [] # Open brackets

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

for ch in s:
# Open bracket
if ch in close_to_open.values():
stack.append(ch)
# Close bracket
else:
if len(stack) == 0:
return False

expected = close_to_open[ch]
if stack.pop() != expected:
return False

return len(stack) == 0

# Time Complexity: O(n)
# Space Complexity: O(n)
Loading