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