Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

&nbsp;
Example 1:
Input: s = "leetcode"
Output: 0
Example 2:
Input: s = "loveleetcode"
Output: 2
Example 3:
Input: s = "aabb"
Output: -1

&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 105
	s consists of only lowercase English letters.


class Solution:
    def firstUniqChar(self, s: str) -> int:
        ls=[]
        for i in range(len(s)):
            x=s.count(s[i])
            if x==1:
                return i
        return -1
class Solution {
    public int firstUniqChar(String s) {
        HashMap<Character,Integer>hmap=new HashMap<>();
        for(int i=0;i<s.length();i++){
            if(!hmap.containsKey(s.charAt(i))){
                hmap.put(s.charAt(i),1);
            }
                else{
                    hmap.put(s.charAt(i),hmap.get(s.charAt(i))+1);
            }
        }
        for(int i=0;i<s.length();i++){
            if(hmap.get(s.charAt(i))==1)
                return i;
        }
        return -1;
    }
}
class Solution {
public:
int firstUniqChar(string s) {
    unordered_map<char, int> mp;

    for(int i=0; i<s.length(); i++){
        mp[s[i]]++;
    }

    for(int i=0; i<s.length(); i++){
        if(mp[s[i]] == 1){
            return i;
        }
    }

    return -1;
}
};
/**
 * @param {string} s
 * @return {number}
 */

var firstUniqChar = function(s) {
    let dec = {};

    for(let i=0; i < s.length ; i++){
        if(dec[s[i]]){
            dec[s[i]]['counter']++;
        }else{
            dec[s[i]] = {},
            dec[s[i]]['counter'] = 1;
            dec[s[i]]['index'] = i;
        }
    }

    for(let i=0; i < s.length ; i++){
        if(dec[s[i]]['counter'] == 1) {
            return dec[s[i]]['index'];
            break;
        }
    }

    return -1;
};
First Unique Character in a String