My Java Solution


  • 0
       public int firstUniqChar(String s) {
             int[] ch = new int[26];
    
            for(int i=0;i<s.length();i++){
              ch[s.charAt(i)-97]++;
            }
           for(int i=0;i<s.length();i++){
              if(ch[s.charAt(i)-97] == 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.