firstNonRepeatedCharacter( "abcdcd" ) -->
'a'
firstNonRepeatedCharacter( "cbcd" ) -->
'b'
firstNonRepeatedCharacter( "cdcd" ) -->
null
HashMap
. For each character, if there is no value stored in the HashMap
, set it to 1. Else increment the value of the Character
count by 1. HashMap
is 1 . If no characters have count of 1 , return null
public static Character firstNonRepeatedCharacter(String str) { }
C
Java
Python