Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
First non-repeating character
MoyenMap and Set10 min
Write a function firstUniqueChar(text) that returns the first character of the string text that appears in it exactly once. If there is no such character, return null.
- "First" means the leftmost in
text: in'swiss'the answer is'w'. - Letter case matters:
'a'and'A'are different characters. - Every character counts, also spaces, digits and punctuation.
- An emoji such as 🐞 is one character. Return it whole, not half of it.
- An empty string gives
null.
Exemples
firstUniqueChar('swiss')Renvoie 'w'
firstUniqueChar('aabb')Renvoie null
firstUniqueChar('aA')Renvoie 'a'
Chargement de l'éditeur...
- Entrée
firstUniqueChar('swiss')Attendu'w' - Entrée
firstUniqueChar('aabb')Attendunull - Entrée
firstUniqueChar('aA')Attendu'a'
Les tests cachés se lancent à la soumission