First Unique Character
Given a string s, find the first character that appears exactly once in it and return its index.
If every character appears more than once, return -1.
Constraints
1 <= s.length <= 10^5scontains lowercase English letters only.
Examples
Example 1
Input: s = "swiss" Output: 1
s appears three times. w (index 1) and i (index 2) appear once each, and w comes first.
Example 2
Input: s = "aabbcc" Output: -1
Every character repeats, so there is no unique one.
Example 3
Input: s = "level" Output: 2
l and e each appear twice; v at index 2 is the only character that appears once.
JavaScript you'll use: Map and Set Strings and characters
/**
* @param {string} s
* @return {number}
*/
function firstUniqChar(s) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.