Leetcode_387_字符串中的第一个唯一字符_水题

12/23

水题

class Solution {
    
    
    public int firstUniqChar(String s) {
    
    
        int m[]=new int[26];
        for(int i=0;i<s.length();i++){
    
    
            m[s.charAt(i)-'a']++;
        }
        for(int i=0;i<s.length();i++){
    
    
            if(m[s.charAt(i)-'a']==1){
    
    
                return i;
            }
        }
        return -1;
    }
}

猜你喜欢

转载自blog.csdn.net/HDUCheater/article/details/111571403