1055. Shortest Way to Form String
Question
Code
class Solution:
def shortestWay(self, source: str, target: str) -> int:
tp = 0
count = 0
while tp < len(target):
newTp = tp
for i in range(len(source)):
if newTp >= len(target):
break
if source[i] == target[newTp]:
newTp += 1
if newTp == tp:
return -1
tp = newTp
count += 1
return count