2dbi
Home/Oracle/First Non-Repeating Character in a String
OOracle·DSASDE-1Online Assessment

First Non-Repeating Character in a String

Problem

Return the index of the first character that does not repeat; return -1 if none.

Example

"leetcode" -> 0; "aabb" -> -1

Constraints

  • 1 ≤ s.length ≤ 10^5

Approach

Frequency map in one pass, then a second pass for the first count-1 char.

added 6 days ago
LeadersAccount