From 9409d1dad5f200d7551962b30dcd0db8fae5c88e Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 30 Nov 2023 09:05:07 +0100 Subject: [PATCH] vault backup: 2023-11-30 09:05:07 --- Algo/B2/Exercises/String exercise.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Algo/B2/Exercises/String exercise.md b/Algo/B2/Exercises/String exercise.md index 9f18a8c..83b488f 100644 --- a/Algo/B2/Exercises/String exercise.md +++ b/Algo/B2/Exercises/String exercise.md @@ -13,12 +13,13 @@ def search(x: str, s:str) -> int: @params s (str): the string @return: (int): the number of occurences """ - i = 1 - n = len(s) - for loop in range(n): - if s[n] == x: - i += 1 - return i + i = 0 + pos = -1 + while i < len(s) and pos == -1: + if s[i] == c: + pos = i + i += 1 + return pos def search2(s: str, x: str) -> int: """