-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay31.cpp
More file actions
36 lines (30 loc) · 725 Bytes
/
Copy pathDay31.cpp
File metadata and controls
36 lines (30 loc) · 725 Bytes
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
31
32
33
34
35
36
class Solution {
public:
int minDistance(string str1, string str2) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int box[600][600];
memset(box, false, sizeof box);
//cin >> str1 >> str2;
for (int i = 0; i <= str1.length(); i++) {
box[i][0] = i;
}
for (int i = 0; i <= str2.length(); i++) {
box[0][i] = i;
}
for (int i = 1; i <= str1.length(); i++) {
for (int j = 1; j <= str2.length(); j++) {
if (str1[i - 1] == str2[j - 1])
{
box[i][j] = box[i - 1][j - 1];
}
else
{
box[i][j] = min({ box[i - 1][j]+1 , box[i][j - 1]+1 , box[i-1][j - 1]+1 });
}
}
}
int ans;
ans = box[str1.length()][str2.length()];
return ans;
}
};