First Unique Character
Python
Medium
3 views
Problem Description
A string s is provided (no spaces). Output the first character that appears exactly once. If none, output -1.
Output Format
One character or -1.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
mp={}
for ch in s:
mp[ch]=mp.get(ch,0)+1
ans='-1'
for ch in s:
if mp.get(ch,0)==1:
ans=ch
break
sys.stdout.write(ans)
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!