File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
Sprint-2/improve_with_precomputing/count_letters Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,14 @@ def count_letters(s: str) -> int:
22 """
33 count_letters returns the number of letters which only occur in upper case in the passed string.
44 """
5- only_upper = set ()
6- for letter in s :
7- if is_upper_case (letter ):
8- if letter .lower () not in s :
9- only_upper .add (letter )
10- return len (only_upper )
11-
12-
13- def is_upper_case (letter : str ) -> bool :
14- return letter == letter .upper ()
5+ # Create a Set of all characters in the string.
6+ present_chars = set (s )
7+
8+ only_upper_count = 0
9+ # We loop through the unique characters
10+ for char in present_chars :
11+ if char .isupper ():
12+ if char .lower () not in present_chars :
13+ only_upper_count += 1
14+
15+ return only_upper_count
You can’t perform that action at this time.
0 commit comments