Staightforward JavaScript Solution


  • 0
    V
    /**
     * @param {string} s
     * @return {number}
     */
    var firstUniqChar = function(s) {
        var map = {};
        var i;
        for(i = 0; i < s.length; i++) {
            map[s.charAt(i)] = (map[s.charAt(i)] || 0) + 1;
        }
        for(i = 0; i < s.length; i++) {
            if(map[s.charAt(i)] === 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.