diff --git a/CodeWars/Find the missing letter.py b/CodeWars/Find the missing letter.py index adcc132..3b53625 100644 --- a/CodeWars/Find the missing letter.py +++ b/CodeWars/Find the missing letter.py @@ -1,19 +1,7 @@ def find_missing_letter(chars): - prev_ord = False + for i in range(1, len(chars)): + if ord(chars[i]) - ord(chars[i - 1]) > 1: + return chr(ord(chars[i - 1]) + 1) - for char in chars: - if prev_ord is False: - prev_ord = True - prev_ord = ord(char) - - else: - present_ord = ord(char) - - if present_ord - prev_ord != 1: - return chr(present_ord - 1) - - prev_ord = present_ord - - -print(find_missing_letter(['a', 'b', 'c', 'd', 'f'])) # e -print(find_missing_letter(['O', 'Q', 'R', 'S'])) # P +print(find_missing_letter(['a', 'b', 'c', 'd', 'f'])) # e +print(find_missing_letter(['O', 'Q', 'R', 'S']))