Skip to content

Commit a86a983

Browse files
authored
Update Minimum Additions to Make Valid String.py
1 parent 8867b76 commit a86a983

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Minimum Additions to Make Valid String.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77

88
class Solution:
99
def addMinimum(self, word: str) -> int:
10-
it = 0
11-
result = 0
12-
while it < len(word) :
13-
if word[it:it+3] == "abc":
14-
it += 3
15-
elif word[it:it+2] in ["ab","ac","bc"]:
16-
result += 1
17-
it += 2
10+
11+
res = 0
12+
i = 0
13+
while i < len(word):
14+
15+
if word[i:i+3]=='abc':
16+
i+=3
17+
elif word[i:i+2] == 'ab' or word[i:i+2] == 'bc' or word[i:i+2]=='ac':
18+
i+=2
19+
res+=1
1820
else:
19-
result += 2
20-
it += 1
21-
return result
22-
21+
i+=1
22+
res+=2
23+
24+
return res

0 commit comments

Comments
 (0)