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
26 changes: 26 additions & 0 deletions longest-increasing-subsequence/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 이 코드는 최장 증가 부분 수열(LIS) 문제를 해결하기 위해 DP를 사용하며, 이전 계산값을 저장하여 효율적으로 문제를 해결하는 패턴입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
'''
모르겠어서 풀이봤습니다 ㅜㅜ
1.problem: 증가하는 가장 긴 subsequence length return (최장 증가 부분 수열)
2.조건
- nums array 길이 최소 1 , 최대 2500
- 원소 값 음수 가능
3.풀이
- dp : time complexity O(n^2)
dp[i] = i번째 원소를 마지막으로하는 LIS
dp[i] max(dp[i], dp[j]+1) 나 보다 작은 애들 중 가장 긴 LIS + 1
'''

n = len(nums)
dp = [1] * (n)

for i in range(n):
for j in range(i):
#앞 숫자 nums[j]가 지금 nums[i]보다 더 작은 경우 dp[i] update
if nums[j] < nums[i]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)



37 changes: 37 additions & 0 deletions valid-parentheses/hyeri0903.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 / Priority Queue
  • 설명: 이 코드는 괄호의 유효성을 검사하기 위해 스택을 이용하여 열린 괄호를 저장하고, 닫힌 괄호와 비교하는 방식으로 문제를 해결합니다. 스택 자료구조를 활용한 대표적인 패턴입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Solution:
def isValid(self, s: str) -> bool:
'''
문제: string s 에 대해서 valid parentheses 이면 true 아니면 false
conditions
- open brackets must be closed by the same type
- // must be closed in the correct order
- s 최소 길이 = 1, 최대 10^4
solution
- open brackets -> st array 에 저장, close brackets -> st.pop -> check valid
- 마지막에 st array length 가 1 이상이면 return False

- time complexity: O(n)
- space complexity: O(n)
'''

st = []

for i in range(len(s)):
if s[i] == '(' or s[i] == '{' or s[i] == '[':
st.append(s[i])
else:
# check if st is empty
if len(st) <= 0:
return False
cur = st.pop()
if s[i] == ')' and cur != '(':
return False
if s[i] == '}' and cur != '{':
return False
if s[i] == ']' and cur != '[':
return False
if len(st) > 0:
return False
return True


Loading