0387. First Unique Character in a String
Description
**Input:** s = "leetcode"
**Output:** 0**Input:** s = "loveleetcode"
**Output:** 2**Input:** s = "aabb"
**Output:** -1ac
Last updated
**Input:** s = "leetcode"
**Output:** 0**Input:** s = "loveleetcode"
**Output:** 2**Input:** s = "aabb"
**Output:** -1Last updated
class Solution {
public int firstUniqChar(String s) {
// edge case
if (s == null || s.length() == 0) return -1;
int[] note = new int[26];
for (int i = 0; i < s.length(); i++) {
note[s.charAt(i) - 'a']++;
}
for (int i = 0; i < s.length(); i++) {
if (note[s.charAt(i) - 'a'] == 1) {
return i;
}
}
return -1;
}
}