Implement the method firstNonRepeatingChar that returns the first non-repeating character in a string.
Return the first character that appears exactly once in the string. The first unique character is determined by original order.
The task is designed to test careful handling of edge cases, not only the most common input.
- Return
#if every character repeats. - Character matching is case-sensitive.
- Spaces and punctuation are treated like normal characters when they appear.
Example 1
Input
s (string) =
swissReturns (char)
wExample 2
Input
s (string) =
developerReturns (char)
dExample 3
Input
s (string) =
aabbccReturns (char)
#Example 4
Input
s (string) =
learningReturns (char)
lCount the frequency of every character, then scan the string again and return the first character whose frequency is one.
Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run