Beats 85% submissions, 24ms


  • 0
    P
    public class Solution {
        public int firstUniqChar(String s) {
            int [] alphabets = new int[26];
            char[] sc = s.toCharArray();
            for(char c:sc) {alphabets[(int)c - (int)'a']++;}
            for(int i=0; i<sc.length; i++) {if(alphabets[(int)sc[i] - (int)'a']==1) return i;}
             return -1;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.