Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # TODO: opravit tuto funkci
  2. def find_substring(string: str, substring: str) -> int:
  3.     """Funkce hleda podretezec (substring) v retezci (string).
  4.    Pokud se podretezec v retezci nachazi, vrati index prvniho vyskytu.
  5.    Jinak vraci -1.
  6.    """
  7.     if len(substring) > len(string):
  8.         return -1
  9.  
  10.     j = 0
  11.     i = 0
  12.     while i < len(string):
  13.         if string[i] == substring[j]:
  14.             if j == len(substring) - 1:
  15.                 return i - j
  16.             j += 1
  17.         i += 1
  18.     return -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement