Beats 96.44% of java submissions


  • 0
    F
    public class Solution {
        public int firstUniqChar(String s) {
            if (s == null) {
                return 0;
            }
            
            int[] hash = new int[26];
            char[] array = s.toCharArray();
            for (char ch : array) {
                hash[ch - 'a']++;
            }
            int index = 0;
            for (char ch : array) {
                index++;
                if (hash[ch - 'a'] == 1) {
                    return index - 1;
                }
            }
            return -1;
            
        }
    }
    

Log in to reply
 

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