Simple Java solution using ASCII indexing


  • 0
    A
            int [] occurenceMap = new int[256];
    
            for(char c: s.toCharArray()){
                occurenceMap[c]++;
            }
    
            for (char c: s.toCharArray()){
                if(occurenceMap[c] == 1){
                    return s.indexOf(c);
                }
            }
            return -1;
    

Log in to reply
 

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