代码如下:
//找出字符串中第一个不重复的字符
// firstUniqueChar("vdctdvc"); --> t
function firstUniqueChar(str){
var str = str || "",
i = 0,
k = "",
_char = "",
charMap = {},
result = {name: "",index: str.length};
for(i=0;i
if(charMap[_char] != undefined){
charMap[_char] = -1;
}else{
charMap[_char] = i;
}
}
for(k in charMap){
if(charMap[k]<0){
continue;
}
if(result.index>charMap[k]){
result.index = charMap[k];
result.name = k;
}
}
return result.name;
}
小伙伴们如有更好的思路,还请告之一下,不胜感激
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com