Problem · String
First Non-Repeating Character
Learn this problemProblem statement
Given a non-empty string text containing lowercase English letters, return its first character that occurs exactly once.
The first character is determined by its position in text, not by alphabetical order. If every character repeats, return the empty string "".
Function
firstNonRepeatingCharacter(text: String) → StringExamples
Example 1
text = "swiss"return = "w"The letter s repeats. The next character, w, occurs once, so it is the first non-repeating character.
Example 2
text = "aabbc"return = "c"Both a and b occur twice, while c occurs once.
Example 3
text = "aabb"return = ""No character occurs exactly once, so the result is the empty string.
Constraints
1 <= text.length <= 10^5textcontains only lowercase English letters.