Created
February 18, 2025 09:22
-
-
Save ichux/129ec65b32b2dbbf4f3f857638070ccd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def non_repeating(data): | |
count = {} | |
# First pass: Count occurrences | |
for char in data: | |
count[char] = count.get(char, 0) + 1 | |
# Second pass: Find the first non-repeating character | |
for char in data: | |
if count[char] == 1: | |
return char | |
return None | |
if __name__ == "__main__": | |
print(non_repeating("abcda")) | |
print(non_repeating("aabcd")) | |
print(non_repeating("hello")) | |
# abcda -> b | |
# aabcd -> b | |
# hello -> h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment