Created
January 12, 2018 00:39
-
-
Save gt50/added5470651e7e54c17a73a62129c86 to your computer and use it in GitHub Desktop.
willmadison challenge
This file contains 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
s = "abacabaabacaba" | |
sset = sorted(set(s), key=s.index) | |
for i in sset: | |
count = 0 | |
for j in s: | |
if j == i: | |
count += 1 | |
if count == 1: | |
print(i) | |
break | |
else: | |
print("_") | |
# Note: Write a solution that only iterates over the string once and uses O(1) additional memory, since this is what you would be asked to do during a real interview. | |
# | |
# Given a string s, find and return the first instance of a non-repeating character in it. If there is no such character, return '_'. | |
# | |
# Example | |
# | |
# For s = "abacabad", the output should be | |
# firstNotRepeatingCharacter(s) = 'c'. | |
# | |
# There are 2 non-repeating characters in the string: 'c' and 'd'. Return c since it appears in the string first. | |
# | |
# For s = "abacabaabacaba", the output should be | |
# firstNotRepeatingCharacter(s) = '_'. | |
# | |
# There are no characters in this string that do not repeat. | |
# | |
# Input/Output | |
# | |
# [execution time limit] 4 seconds (go) | |
# | |
# [input] string s | |
# | |
# A string that contains only lowercase English letters. | |
# | |
# Guaranteed constraints: | |
# 1 ≤ s.length ≤ 105. | |
# | |
# [output] char | |
# | |
# The first non-repeating character in s, or '_' if there are no characters that do not repeat. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment