Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1.
在字串中,找出第一個不重複的字元。
s = "leetcode"
return 0.
s = "loveleetcode"
return 2.
如果是唯一值的話,從頭搜尋的索引值會等於從尾搜尋的索引值。
var firstUniqChar = function(s) {
for (let i = 0; i < s.length; i++) {
if (s.indexOf(s.charAt(i)) === s.lastIndexOf(s.charAt(i))) {
return i;
}
}
return -1;
};