public class Solution { public int FirstNotRepeatingChar(String str) { if(str == null || str.length() == 0){ return -1; } int[] pos = new int['z' - 'A' + 1]; int[] cnt = new int['z' - 'A' + 1]; for(int i = 0; i < str.length(); ++i){ char c = str.charAt(i); pos[c - 'A'] = i; cnt[c - 'A']++; } int index = 0; while(index <= str.length() - 1){ if(cnt[str.charAt(index) - 'A'] == 1){ return pos[str.charAt(index) - 'A']; } index++; } return -1; } }