-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppend and Delete.py
33 lines (28 loc) · 1.01 KB
/
Append and Delete.py
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
def appendAndDelete(s, t, k):
# đếm kí tự lặp
the_same_count = 0
# dùng function zip để do theo cặp trong string s và t
for (i,j) in zip(s,t):
if i == j:
# nếu giống thì counter +1
the_same_count += 1
else:
# không giống nghĩa là phải dừng lại và xóa từ đó
break
# Tính kí tự phải xóa
delete_cha = len(s) - the_same_count
# tính kí tự add thêm
add_cha = len(t) - the_same_count
if (delete_cha + add_cha) == k or k > (len(s) + len(t)):
return "Yes"
elif (delete_cha + add_cha) < k:
total_de_ad = delete_cha + add_cha
while total_de_ad < k:
total_de_ad += 2
if total_de_ad == k:
return "Yes"
elif total_de_ad >k and delete_cha < len(s):
return "No"
return "Yes"
else:
return "No"