All files / leetCode 0387.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  3x   3x 24x 24x 9x 15x     3x 6x 2x     1x    
export default function firstUniqChar(s: string): number {
  const map = new Map<string, number>()
 
  for (let i = 0; i < s.length; i++) {
    const char = s[i]
    if (map.has(char))
      map.set(char, -1)
    else map.set(char, i)
  }
 
  for (const index of map.values()) {
    if (index !== -1)
      return index
  }
 
  return -1
}