일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- kaggle
- Generator
- 시바견
- DWG
- concurrency
- Protocol
- 315. Count of Smaller Numbers After Self
- t1
- 109. Convert Sorted List to Binary Search Tree
- 715. Range Module
- shiba
- Decorator
- attribute
- Regular Expression
- iterator
- 파이썬
- 운영체제
- Python Implementation
- 밴픽
- 컴퓨터의 구조
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- LeetCode
- 프로그래머스
- Class
- data science
- Python Code
- Python
- 43. Multiply Strings
Archives
- Today
- Total
Scribbling
LeetCode: 72. Edit Distance 본문
class Solution:
def minDistance(self, word1: str, word2: str) -> int:
m, n = len(word1), len(word2)
dp = [[0] * (m+1) for _ in range(n+1)]
for i in range(1, m+1):
dp[0][i] = i
for i in range(1, n+1):
dp[i][0] = i
for i in range(1, n+1):
for j in range(1, m+1):
if word1[j-1] != word2[i-1]:
dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1
else:
dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]+1, dp[i][j-1]+1)
return dp[n][m]
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 74. Search a 2D Matrix (0) | 2021.09.28 |
---|---|
LeetCode: 73. Set Matrix Zeroes (0) | 2021.09.28 |
LeetCode: 71. Simplify Path (0) | 2021.09.26 |
LeetCode: 69. Sqrt(x) (0) | 2021.09.26 |
LeetCode: 67. Add Binary (0) | 2021.09.26 |