156. Find the First Non-Repeating Character

EasyStringString

Given a string s, find and return the first character that does not repeat anywhere in the string.

If every character repeats, return an empty string ''.

The check is case-sensitive.

Input: A single string s.

Output: A single character string — the first non-repeating character, or '' if all characters repeat.

Examples

Example 1
Input: leetcode
Output: l
Explanation: Frequency: l=1,e=3,t=1,c=1,o=1,d=1. First character with freq=1 is 'l' (index 0).
Example 2
Input: loveleetcode
Output: v
Explanation: l=2,o=2,v=1,... First non-repeating is 'v' at index 2.
Example 3
Input: aabb
Output: 
Explanation: a appears twice, b appears twice — no non-repeating character.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →