LeetCode387. 字符串中的第一个唯一字符
1 class Solution { 2 public int firstUniqChar(String s) { 3 4 int[] freq = new int[26]; 5 for(int i = 0; i < s.length(); i ++){ 6 freq[s.charAt(i) - 'a'] ++; 7 } 8 for(int i = 0; i < s.length(); i ++){ 9 if(freq[s.charAt(i) - 'a'] == 1){ 10 return i; 11 } 12 } 13 return -1; 14 15 } 16 }