You need to write a function, which will accept a String and return first non-repeated character, for example in the world "hello", except 'l' all are non-repeated, but 'h' is the first non-repeated character. Similarly, in word "swiss" 'w' is the first non-repeated character. One way to solve this problem is creating a table to store count of each character, and then picking the first entry which is not repeated. The key thing to remember is order, your code must return first non-repeated letter.

 public class solution {
public char firstNonRepeating(String s) {
char result = '#';
if (s == null || s.length == 0) {
return result;
}
Map<Character,Integer> map = HashMap<>();
for (int i = 0; i < s.length(); i++) {
if (map.containsKey(s.charAt(i))) {
map.put(s.charAt(i), map.get(s.charAt(i)) + 1);
} else {
map.put(s.charAt(i), 1);
}
} for (int i = 0; i < s.length; i++) {
if (map.get(s.charAt(i) == 1)) {
result = s.charAt(i);
return result;
}
}
return result;
}
}
05-29 00:50