Skip to content

Commit

Permalink
70.py
Browse files Browse the repository at this point in the history
  • Loading branch information
huisuu committed Aug 31, 2024
1 parent ccbda0d commit 6ad52eb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions HSKIM/61to70/70.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def solution(str1, str2):
n = len(str1)
m = len(str2)

dp = [[0]*(n + 1) for _ in range(m + 1)]

# LCS 길이 계산
for i in range(1, m + 1):
for j in range(1, n + 1):
# 문자가 같은 경우
if str2[i-1] == str1[j-1]:
dp[i][j] += dp[i-1][j-1] + 1
# 문자가 다른 경우
else:
dp[i][j] = max(dp[i][j-1], dp[i-1][j])

return dp[m][n]

print(solution("ABCBDAB", "BDCAB"))

0 comments on commit 6ad52eb

Please sign in to comment.