Advertisement
jbn6972

Untitled

Sep 10th, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. def getSmallestString(word,substr):
  2.     for i in range(len(word)):
  3.         if word[i] == "?":
  4.             start = i
  5.             end = start
  6.             while word[end] == "?":
  7.                 end += 1
  8.            
  9.             # print(word[end])
  10.             if word[end] in substr:
  11.                 if substr.index(word[end]) == abs(start-end):
  12.                     # word[start:end] = substr[:substr.index(word[end])]
  13.                     word = word.replace(word[start:end],substr[:substr.index(word[end])],1)
  14.                     print(word)
  15.                 else:
  16.                     if len(substr[substr.index(word[end]):]) >= abs(start-end):
  17.                         word = word.replace(word[start:end],substr[substr.index(word[end]):substr.index(word[end])+abs(start-end)],1)
  18.  
  19.             else:
  20.                 return -1
  21.  
  22.     return word
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement