/*****************************************************问题描述*************************************************
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
给定一个字符串,找出字符串中第一个不重复的字符,返回它的索引,没有返回-1
/*****************************************************我的解答*************************************************
/**
* @param {string} s
* @return {number}
*/
var firstUniqChar = function(s) {
for(var index = 0; index < s.length; index++)
{
var reg = new RegExp(s.charAt(index),'g');
if(s.match(reg).length == 1)
{
return index;
}
}
return -1;
};