Skip to content

Commit fa9d759

Browse files
committed
[BOJ] #5582.공통부분 문자열 / 골드5 / 60(∆)
1 parent eba8109 commit fa9d759

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
S1 = list(input().strip())
5+
S2 = list(input().strip())
6+
n, m = len(S1), len(S2)
7+
8+
dp = [[0] * (m+1) for _ in range(n+1)]
9+
10+
max_len = 0
11+
12+
for i in range(1, n+1):
13+
for j in range(1, m+1):
14+
# 문자열 S1과 S2의 현재 위치의 문자를 비교
15+
if S1[i-1] == S2[j-1]:
16+
dp[i][j] = dp[i-1][j-1] + 1 # 이전 공통 부분 문자열에 현재 문자를 추가하여 길이를 연장
17+
max_len = max(max_len, dp[i][j])
18+
else:
19+
dp[i][j] = 0 # 다르면 공통 부분 문자열이 끊어짐
20+
21+
print(max_len)

0 commit comments

Comments
 (0)