Java 14ms solution beats 99% ASCII, easy to understand


  • 0
    J
    public int firstUniqChar(String s) {
        int[] table = new int[128];
        for (char c : s.toCharArray()) {
            table[c]++;
        }
        int rst = 0;
        for (char c : s.toCharArray()) {
            if (table[c] == 1) return rst;
            rst++;
        }
        
        return -1;
    }

Log in to reply
 

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